Welcome to the Command Line Cheat Sheet! This comprehensive guide is designed to assist both beginners and experienced users in navigating the command line interface efficiently. Whether you're managing files and directories, working with permissions, or diving into network and remote connections, this cheat sheet provides a quick reference for essential commands of Linux.
- Commands are presented in the format used in a bash terminal.
- Explanatory notes are provided in paragraph format to give you a clear understanding of each command's functionality.
Detailed information about a user (uid, gid, and group).
idLists information about recent logins, including time, username, IP address, and session duration.
lastDisplays authorized users.
whoCreates a group named "testgroup".
groupadd "testgroup"Adds a user with the name "NewUser".
adduser NewUserDeletes the user with the name "NewUser".
userdel NewUserModifies information about the user "NewUser".
usermod NewUserNavigate to the root directory.
cd /Navigate to the home directory (using the $HOME variable).
cd ~Navigate to the /root directory.
cd /rootMove one level up.
cd ..Navigate to the hidden folder .ssh.
cd /root/.sshDisplays files and directories in the current folder.
ls -alShows the current working directory.
pwdCreates a new directory named 'NewFolder'.
mkdir NewFolderDeletes the file named 'NewFile'.
rm NewFileForcefully deletes the file named 'NewFile'.
rm -f NewFileRecursively deletes the directory named 'NewFolder'.
rm -r NewFolderForcefully and recursively deletes the directory named 'NewFolder'.
rm -rf NewFolderCopies the content of 'oldfile1' to 'newfile2'.
cp oldfile1 newfile2Recursively copies the directory 'olddir1' to 'newdir2'. Dir2 will be created if it doesn't exist.
cp -r olddir1 newdir2Renames 'oldfile1' to 'newfile2'.
mv oldfile1 newfile2Creates a symbolic link to the file.
ln -s /etc/log/file logfileCreates an empty file named 'newfile'.
touch newfileTakes STDIN and puts it into 'newfile'.
cat > newfileOutputs the content of 'newfile' one screen at a time.
more newfileOutputs the first 10 lines of the file 'newfile'.
head newfileOutputs the last 10 lines of 'newfile'.
tail newfileEncrypts 'newfile' in gpg format using a password and saves it in the same directory.
gpg -c newfileDecrypts the gpg file.
gpg newfile.gpgDisplays the count of bytes, words, and lines in the new file.
wc newfileSets read, write, and execute permissions for everyone who has access to the server (owner, group, others).
chmod 777 /root/sshConfigures permissions as rwx for the owner and r_x for the group and others.
chmod 755 /root/sshSets rwx for the owner and rw for the group and others.
chmod 766 /root/sshChanges the owner of newfile to newuser.
chown newuser newfileChanges both the owner and group owner of newfile to newuser and newgroup.
chown newuser:newgroup newfileChanges both the owner and group owner of the directory newfolder to newuser and newgroup.
chown newuser:newgroup newfolderDisplays the user and group owners of newfile.
stat -c "%U %G" newfileSearches for the searchargument in newfile.
grep searchargument newfileRecursively searches for the searchargument in all files within the newfolder.
grep -r searchargument newfolderShows all locations of the newfile.
locate newfileFinds files with names starting with searchargument in the /etc directory.
find /etc/ -name "searchargument"Finds files larger than 50000k in size in the /etc directory.
find /etc/ -size +50000kCreate an archive 'archive.tar' from the file 'newfile.'
tar -cf archive.tar newfileExtract the contents of the file 'archive.tar.'
tar -xf archive.tarCreate an archive from the /var/log/ directory and compress it using gzip.
tar -zcvf archive.tar.gz /var/log/Compress the new file (it will have the extension .gz).
gzip newfileInstalls an RPM package on CentOS, RHEL, etc.
rpm -i pkg_program.rpmRemoves an RPM package on CentOS, RHEL, etc.
rpm -e pkg_nameInstalls a package using DNF from the repository on CentOS, RHEL, etc. YUM was previously used, but it has recently been replaced by DNF.
dnf install pkg_nameInstalls from a DEB package on Debian, Ubuntu, Mint, etc.
dpkg -i pkg_nameRemoves a DEB package on Debian, Ubuntu, Mint, etc.
dpkg -r pkg_nameInstalls a package from the repository on Debian, Ubuntu, Mint, etc.
apt install pkg_nameRemoves a package on Debian, Ubuntu, Mint, etc.
apt remove pkg_nameUpdates the packages in the system (Debian, Ubuntu, Mint, etc.) and updates the repositories.
apt upgrade && apt updateDisplays currently running processes.
psFinds the process ID (PID) of 'bash'.
ps aux | grep 'bash'Maps the process with PID 11 in process memory.
pmap -x 11Shows all running processes.
topTerminates a process by PID.
kill pidTerminates all processes with the name "process".
killall processSends a signal to a process by name.
pkill process-nameSends a suspended process to the background.
bgBrings a running process to the foreground.
fgBrings a process named "process" to the foreground.
fg processLists files opened by processes.
lsofSets the lowest priority for a process.
renice 19 PIDFinds the process ID for 'bash'.
pgrep bashShows a tree-like representation of processes.
pstreeDisplays system information.
unameShows information about the Linux kernel.
uname -rShows system uptime and average load.
uptimeDisplays the host name.
hostnameDisplays the host's IP address.
hostname -iShows the reboot history.
last rebootDisplays date and time.
dateOutputs and modifies date and time settings.
timedatectlDisplays the calendar.
calShows users currently logged in.
wDisplays your username.
whoamiShows information about the root user (requires installation with "apt-get install finger").
finger rootDisplays system messages during boot.
dmesgShows information about the processor.
cat /proc/cpuinfoDisplays information about the memory.
cat /proc/meminfoShows detailed information about devices.
lshwDisplays information about block devices.
lsblkFrees up memory: RAM and swap (switch -m for MB).
free -mShows PCI device information in a tree view.
lspci -tvDisplays USB devices in a tree view.
lsusb -tvShows information about BIOS devices.
dmidecodeDisplays information about the disk.
hdparm -i /dev/xdaShows read and write speed of xda.
hdparm -tT /dev/xdaPerforms a test for bad sectors.
badblocks -s /dev/xdaShows free space on mounted partitions (in bytes).
df -hDisplays free inodes in the file system.
df -iProvides information about the disk, partitions, and file system.
fdisk -lShows undistributed space on mounted partitions in MB, GB, TB.
du -shDisplays all mount points.
findmntMounts partition 1 of sdb disk to the /mnt directory.
mount /dev/sdb1 /mntDisplays the IP addresses of all available network interfaces.
ip addr showAssigns the address 192.168.0.1 to the eth0 interface.
ip address add 192.168.0.1/24 dev eth0Shows the IP addresses of all available network interfaces.
ifconfigSends an ICMP protocol request to connect to the node at 192.168.0.1.
ping 192.168.0.1Displays information about the
whois domainRetrieves DNS information about the domain.
dig domainPerforms reverse DNS resolution.
dig -x 192.168.0.1Resolves the host address.
host serverspace.usShows local addresses.
hostname -IDownloads a file.
wget file_name(link to file)Displays all ports being listened to on the host (requires "apt-get install net-tools").
netstat -pnltuConnects to a remote host via ssh as the root user.
ssh root@hostConnects to a remote host using a non-default ssh port, specifying the user.
ssh -p port_number user@hostUtilizes the default connection using the current user.
ssh hostUses a telnet connection (port 23).
telnet host