The shell (or terminal) in Linux is a power user’s and a developer’s lifeline. Using commands on the terminal is a far more effective way to carry out actions that may be carried out on the GUI (by clicking on various buttons). One may not be able to recall every command, but with consistent use, one may quickly recall the ones that are most useful.
File Commands
Command
Short Description
ls
list files in directory
ls -a
list all files, including hidden
pwd
show the directory currently working in
mkdir [directory]
create a new directory
rm [file_name]
remove a file
rm -r [directory_name]
remove a directory recursively
rm -rf [directory_name]
remove a directory recursively without requiring confirmation
cp [file_name1] [file_name2]
copy the contents of the first file to the second file
cp -r [directory_name1] [directory_name2]
recursively copy the contents of the first directory into the second directory
mv [file_name1] [file_name2]
rename file_name1 to file_name2
ln -s /path/to/[file_name] [link_name]
create a symbolic link to a file
touch [file_name]
create a new file
more [file_name]
show the contents of a file
head [file_name]
show the first 10 lines of a file
tail [file_name]
show the last 10 lines of a file
gpg -c [file_name]
encrypt a file
gpg [file_name.gpg]
decrypt a file
wc
print the number of words, lines, and bytes in a file
File Commands
Disk Usage
Command
Short Description
df -h
show free and used space on mounted systems
df -i
show free inodes on mounted filesystems
fdisk -l
show disk partitions, sizes, and types
du -ah
show disk usage for all files and directory
du -sh
show disk usage of current directory
findmnt
show target mount point for all filesystems
mount [device_path] [mount_point]
Untitled mount a device
Disk Usage
File Permission
Command
Short Description
chmod 777 [file_name]
give read, write, and execute permission to everyone
chmod 755 [file_name]
give full permission to owner, and read and execute permission to group and others
chmod 766 [file_name]
give full permission to owner, and read and write permission to group and others
chown [user] [file_name]
change the file ownership
chown [user]: [group] [file_name]
change the owner and group ownership of a file
File Permission
Directory Navigation
Command
Short Description
cd ..
move up one level in the directory tree structure
cd
change directory to $HOME
cd /chosen/directory
change to specified directory
Directory Navigation
Keyboard Shortcuts
Command
Short Description
Ctrl + C
kill current process running in the terminal
Ctrl +Z
stop current process (can be resumed in the foreground with fg or in the background with bg)
Ctrl +W
cut one word before the cursor and add it to clipboard
Ctrl +U
cut part of the line before the cursor and add it to clipboard
Ctrl +K
cut part of the line after the cursor and add it to clipboard
Ctrl +Y
paste from clipboard
Ctrl +R
recall last command that matches the provided characters
Ctrl +O
run the previously recalled command
Ctrl +G
exit command history without running a command
!!
repeat the last command
exit
log out of current session
Keyboard shortcuts
Hardware Information
Command
Short Description
dmesg
show bootup messages
cat /proc/cpuinfo
show CPU information
free -h
show free and used memory (-m flag indicates memory in MB)
lshw
list information about hardware configuration
lsblk
list information about block devices
lspci -tv
show PCI devices in a tree-like diagram
lsusb -tv
show USB devices in a tree-like diagram
dmidecode
show hardware information from the BIOS
hdparm -i /dev/[disk]
show information about disk data
hdparm -tT /dev/[disk]
conduct a read speed test on disk
badblocks -s /dev/[disk]
test for unreadable blocks on disk
Hardware Information
System Information
Command
Short Description
uname -r
show system information
uname -a
show kernel release information
uptime
show how long the system has been running, including load average
hostname
show system hostname
hostname -i
show the IP address of the system
last reboot
show system reboot history
date
show current time and date
timedatectl
query and change the system clock
cal
show current calender month and day
w
show logged in users in the system
whoami
show user you are using
finger [username]
show information about a user
System Information
Searching
Command
Short Description
grep [pattern] [file_name]
search for a specific pattern in a file
grep -r [pattern] [directory_name]
search recursively for a specific pattern in a directory
locate [name]
find all files and directories by a specific name
find [/folder/location] -name [a]
list names that begin with [a] in [/folder/location]
find [/folder/location] -size [+100M]
list files larger than 100M in a particular folder
Leave a Reply