Linux Command Cheat Sheet

Published on Author craigzearfossLeave a comment
cancel <job-id_or_printer-name> Cancel lprm commands; it only removes your active jobs – = remove all jobs, not just yours
cat -b filename Display the contents of a file -b = show line numbers
cd – Go to last directory
cd ~ Go to the home directory
cd ~username Go to home directory of username
cd dirname Go to dirname directory
chmod g=rwx filename(s) Grant group access of read, write and execute to a file or directory You can also specify “+” or “-“
chmod o=rwx filename(s) Grant others access of read, write and execute to a file or directory You can also specify “+” or “-“
chmod u=rwx filename(s) Grant user access of read, write and execute to a file or directory You can also specify “+” or “-“
chmod ug+s dirname(s) Set the Set User ID (SUID) and Set Group ID (SGID) bits for a directory
chmod ug+s filename(s) Set the Set User ID (SUID) and Set Group ID (SGID) bits for a file
chown user filename(s) Change ownership of a file You can specify multiple files
cp source_file destination_file Copy a file
du -h | grep M | sort -nr | head -15 Find largest files -h = human readable
-n = numeric sort
-r = reverse results
15 = only show top 15 results
df -h View mounted volumes
du -ch | grep total Show total directory size -c = display grand total
-h = human readable
find . -type d -exec chmod 755 {}; Fix directory permissions recursively . = current folder
-type d = find only directories
-exec = run the following command on the results
find . -type f -exec chmod 644 {}; Fix file permissions recursively . = current folder
-type f = find only files
-exec = run the following command on the results
grep pattern file(s) Search file(s) for lines that have a certain pattern -v = all lines that do not match pattern
-n = include line numbers
-l = only show files names with matching lines
-c = only show matching line count
-i = case insensitive
fuser -u /nas01/ List the user on the device /nas01
grep -ril “TEXT TO FIND” /path/to/search Find text in files and only only list filenames -r = recursive
-i = case-insensitive
-l = list filenames
halt Shut down system down immediately (superuser or root)
ifconfig
init 0 Shut down system using predefined scripts to synchronize and clean up the system prior to shutdown (superuser or root)
init 6 Reboots the system by shutting it down completely and then bringing it completely back up (superuser or root)
ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s/\/.*$//’ Find a server’s public IP address
logout Log out of the system
lp print-job Show an ID that you can use to cancel the print job or check its status nNum = number of copies
-dprinter = printer if there are multiple ones
lp print-job Show an ID that you can use to cancel the print job or check its status -Num = number of copies
-Pprinter = printer if there are multiple ones
lpq -o Show what’s in the printer queue; See also lpstat -o = see all output requests
lpstat -o Show what’s in the printer queue; See also lpq -o = see all output requests
ls -l List files and directories
ls -Rlh | grep YYYY-MM-DD | sort -k 5,6 Find files with specific modified date -R = recursive
-l = long format
-h = human readable units
ls -1 | wc -l Count files-1 = force display to one line per file -l = count lines; For recursive count: ls -1R | wc -l
ls -l | grep ^d List only directories
ls -l | grep ^- List only files
lsblk List all attached block devices; use sudo fdisk -l | grep Disk on systems that don’t support lsblk
lsof | grep ‘/dev/sda1’ List open files on the device /dev/sda1
mail Check if email is installed
mail [-s subject] [-c cc-addr] [-b bcc-addr] to-addr Send email; type in your message, followed by an “control-D” at the beginning of a line. To stop simply type dot. -s = subject
-c = comma separated carbon copies
-b = comma separated blind carbon copies
mkdir -p dirname(s) Create a directory and necessary parent directories
You can specify multiple directories
-p = create parent directories if they do not exist
mkdir dirname(s) Create a directory
You can specify multiple directories
sudo mkfs -t ext4 <volume> Format a volume; Ex. sudo mkfs -t ext4 /dev/xvdf
sudo mount <device> <mount_directory> Mount a device; Ex. sudo mount /dev/xvdf /mnt/my-data
mv old_file new_file Rename a file
passwd Change password
poweroff Shuts down the system by powering off (superuser or root)
pr option(s) filename(s) Formats files on the terminal screen or for a printer -k = produce k columns of output
-d = double-space
-h “header” = add report header
-t = no of header or top/bottom margins
-l PAGE_LENGTH = set page length (default 56)
-o MARGIN = set margin
-w PAGE_WIDTH = set page width only for multiple text-column output
ps auxw List processes
reboot Reboots the system (superuser or root)
rm filename(s) Delete a file You can specify multiple files
rmdir dirname(s) Delete a directory You can specify multiple directories
shutdown Shut down the system (superuser or root)
sed ‘s/search_string/search_stringfile_name | grep -c “search_string Search for occurrences of a string in a file
top Monitor process
touch filename Update the access and modification times of each FILE to the current time
umount /dev/sda1 Unmount the device /dev/sda1
sudo update-rc.d nginx defaults Make sure that the nginx web server will restart automatically when the server is rebooted
users List current users
vi filename Edit a file using vi editor
w List current users’ information (more detailed than who)
wc filename(s) Get count of the total number of lines, words, and characters in a file; You can specify multiple files
who List current users’ information

Leave a Reply

Your email address will not be published. Required fields are marked *