GNU Core Utilities (Coreutils) Cheat Sheet ( Base structure & Formatting Generated by Chatgpt )
GNU Coreutils is a package of basic file, shell, and text manipulation utilities. Below is a summary of all tools with examples.
File and Directory Management
find
Get SHA sum from all files in current directory.
find . -type f -exec sha1sum {} \;
ls
List directory contents.
ls
ls -l
ls -a
cp
Copy files and directories.
cp source_file destination
cp -r source_dir destination_dir
mv
Move/rename files and directories.
mv old_name new_name
mv file_name /path/to/destination/
rm
Remove files or directories.
rm file
rm -r directory
mkdir
Create directories.
mkdir new_directory
mkdir -p parent_dir/child_dir
rmdir
Remove empty directories.
rmdir directory_name
File Viewing and Manipulation
cat
Concatenate and display file contents.
cat file.txt
cat file1.txt file2.txt > combined.txt
tac
Display file contents in reverse.
tac file.txt
nl
Number lines of a file.
nl file.txt
head
Display the beginning of a file.
head file.txt
head -n 10 file.txt
tail
Display the end of a file.
tail file.txt
tail -f file.log
wc
Count lines, words, and characters.
wc file.txt
wc -l file.txt
Disk and File System Utilities
df
Report disk space usage.
df
df -h
du
Estimate file space usage.
du
du -h directory_name
File Permissions and Ownership
chmod
Change file permissions.
chmod 644 file.txt
chmod +x script.sh
chown
Change file owner and group.
chown user:group file.txt
Text Processing
xargs
Xargs runs a command against every line of input from STDIN.
Get sha1sum from all files in current dirctory using xargs.
find . -type f | xargs sha1sum
The same but with files that have spaces. Null byte character is added in between file names instead of a newline character. The -0 arg tells xargs to treat null byte charactes as a separator.
find . -type f -print0 | xargs -0 sha1sum
Tell xargs to pipe input line by line into command. This helps when the command appended to xargs expects one line of input from an argument.
Run commands given to xargs in paralell
cat domains.txt | xargs -P4 dig -x
cut
Remove sections from lines of a file.
cut -d':' -f1 /etc/passwd
sort
Sort lines of text files.
sort file.txt
sort -r file.txt
uniq
Filter duplicate lines.
uniq file.txt
uniq -c file.txt
tr
Translate or delete characters.
tr 'a-z' 'A-Z' < file.txt
tr -d '
' < file.txt
paste
Merge lines of files.
paste file1.txt file2.txt
split
Split a file into pieces.
split -l 100 file.txt
System Information
uname
Display system information.
uname
uname -a
uptime
Show system uptime.
uptime
who
Show who is logged in.
who
date
Display or set the date.
date
date '+%Y-%m-%d %H:%M:%S'
hostname
Show or set the system hostname.
hostname
hostname new_hostname
Process Management
ps
Display process information.
ps
ps aux
kill
Terminate processes by PID.
kill 1234
kill -9 1234
top
Show real-time process information.
top
jobs
List active jobs.
jobs
bg
/ fg
Resume jobs in background/foreground.
bg %1
fg %1
User Management
id
Display user and group IDs.
id
id username
whoami
Show the current user.
whoami
Archiving and Compression
tar
Archive files.
tar -cvf archive.tar file
tar -xvf archive.tar
gzip
Compress files.
gzip file
gunzip file.gz
zip
/ unzip
Create or extract zip files.
zip archive.zip file
unzip archive.zip
Networking Utilities
ping
Send ICMP echo requests.
ping example.com
wget
Download files from the web.
wget https://example.com/file
curl
Transfer data from URLs.
curl https://example.com
Miscellaneous
echo
Display text.
echo "Hello, World!"
yes
Output a string repeatedly.
yes
yes | sudo apt-get upgrade
sleep
Delay for a specified time.
sleep 5
time
Measure execution time of a command.
time ls
Note: For more information on any of these commands, use the man
command (e.g., man ls
).