COMMANDS CHEAT SHEET

System File Commands

=> Displays Linux system information ls -al => Lists files - both regular & hidden files and their permissions as well. uname -r => Displays kernel release information pwd => Displays the current directory file path uptime => Displays how long the system has been running including load average mkdir ‘directory_ => Creates a new directory name’ hostname => Shows the system hostname rm file_name => Removes a file hostname -i => Displays the IP address of the system rm -f filename => Forcefully removes a file last reboot => Shows system reboot history rm -r directory_ => Removes a directory recursively date => Displays current system date and time name timedatectl => Query and change the System clock rm -rf directory_ => Removes a directory forcefully and name recursively cal => Displays the current calendar month and day cp file1 file2 => Copies the contents of file1 to file2 w => Displays currently logged in users in the system cp -r dir1 dir2 => Recursively Copies dir1 to dir2. dir2 is whoami => Displays who you are logged in as created if it does not exist finger username => Displays information about the user mv file1 file2 => Renames file1 to file2 ln -s /path/to/ => Creates a symbolic link to file_name file_name link_ Hardware name touch file_name => Creates a new file dmesg => Displays bootup messages cat > file_name => Places standard input into a file cat /proc/cpuinfo => Displays more information about CPU e.g model, more file_name => Outputs the contents of a file model name, cores, vendor id head file_name => Displays the first 10 lines of a file cat /proc/meminfo => Displays more information about hardware mem- ory e.g. Total and Free memory tail file_name => Displays the last 10 lines of a file lshw => Displays information about system’s hardware gpg - file_ => Encrypts a file configuration name lsblk => Displays block devices related information gpg file_name. => Decrypts a file gpg free -m => Displays free and used memory in the system (-m flag indicates memory in MB) wc => Prints the number of bytes, words and lines in a file lspci -tv => Displays PCI devices in a tree-like diagram xargs => Executes commands from standard input lsusb -tv => Displays USB devices in a tree-like diagram dmidecode => Displays hardware information from the BIOS Process Related hdparm -i /dev/ => Displays information about disk data xda

hdparm -tT /dev/ => Conducts a read speed test on device xda ps => Display currently active processes xda badblocks -s /dev/ => Tests for unreadable blocks on disk ps aux | grep => Searches for the id of the process xda ‘telnet’ ‘telnet’ pmap => Displays memory map of processes

top => Displays all running processes Users kill pid => Terminates process with a given pid

killall proc => Kills / Terminates all processes named id => Displays the details of the active user e.g. uid, proc gid, and groups pkill process-name => Sends a signal to a process with its last => Shows the last logins in the system name who => Shows who is logged in to the system bg => Resumes suspended jobs in the back- ground groupadd “admin” => Adds the group ‘admin’ fg => Brings suspended jobs to the fore- adduser “Sam” => Adds user Sam ground userdel “Sam” => Deletes user Sam fg n => Brings job n to the foreground usermod => Used for changing / modifying user information lsof => Lists files that are open by processes

renice 19 PID => Makes a process run with very low priority pgrep firefox => Find Firefox process ID

pstree => Visualizing processes in tree model LINUX COMMANDS CHEAT SHEET

File Permission Install Source (Compilation)

chmod octal => Change file permissions of the file to octal ./configure filename make Example make install chmod 777 /data/ => Set rwx permissions to owner, group and test.c everyone (everyone else who has access to the server) Search chmod 755 /data/ => Set rwx to the owner and r_x to group and test.c everyone chmod 766 /data/ => Sets rwx for owner, rw for group and everyone grep ‘pattern’ files => Search for a given pattern in files test.c grep -r pattern dir => Search recursively for a pattern in a chown owner => Change ownership of the file given directory user-file locate file => Find all instances of the file chown owner- => Change owner and group owner of the file find /home/ -name => Find file names that begin with ‘index’ user: owner-group “index” in /home folder file_name find /home -size => Find files greater than 10000k in the chown owner- => Change owner and group owner of the +10000k home folder user:owner-group- directory directory Login Network ssh user@host => Securely connect to host as user ip addr show => Displays IP addresses and all the network ssh -p port_number => Securely connect to host using a interfaces user@host specified port ip address add => Assigns IP address 192.168.0.1 to interface ssh host => Securely connect to the system via 192.168.0.1/24 eth0 SSH default port 22 dev eth0 telnet host => Connect to host via telnet default port ifconfig => Displays IP addresses of all network interfaces 23 ping host => ping command sends an ICMP echo request to establish a connection to server / PC File Transfer whois domain => Retrieves more information about a domain name dig domain => Retrieves DNS information about the domain scp file1.txt server2/tmp => Securely copy file1.txt to server2 in / tmp directory dig -x host => Performs reverse lookup on a domain rsync -a /home/apps / => Synchronize contents in /home/apps host google.com => Performs an IP lookup for the domain name backup/ directory with /backup directory hostname -i => Displays local IP address wget file_name => Downloads a file from an online source Disk Usage netstat -pnltu => Displays all active listening ports df -h => Displays free space on mounted systems Compression / Archives df -i => Displays free inodes on filesystems fdisk -l => Shows disk partitions, sizes, and types tar -cf home.tar => Creates archive file called ‘home.tar’ from du -sh => Displays disk usage in the current home file ‘home’ directory in a human-readable format tar -xf files.tar => Extract archive file ‘files.tar’ findmnt => Displays target mount point for all tar -zcvf home.tar.gz => Creates gzipped tar archive file from source filesystems source-folder folder mount device-path => Mount a device gzip file => Compression a file with .gz extension mount-point

Install Packages Directory Traverse rpm -i pkg_name.rpm => Install an rpm package cd .. => Move up one level in the directory tree structure rpm -e pkg_name => Removes an rpm package cd => Change directory to $HOME directory dnf install pkg_name => Install package using dnf utility cd /test => Change directory to /test directory