Linux Cheat Sheet

Linux Cheat Sheet

share:

Here is a great list of commonly used Linux commands to help you.

If like me you have a million things going through your head, cheat sheets can be an amazing bible to have to reference.

Take a look at this collection of commands.

File Commands

  • ls -al Lists files – both regular &  hidden files and their permissions as well.
  • pwd Displays the current directory file path
  • mkdir ‘directory_name’ Creates a new directory
  • rm file_name Removes a file
  • rm -f filename Forcefully removes a file
  • rm -r directory_name Removes a directory recursively
  • rm -rf directory_name Removes a directory forcefully and recursively
  • cp file1 file2 Copies the contents of file1 to file2
  • cp -r dir1 dir2 Recursively Copies dir1 to dir2. dir2 is created if it does not exist
  • mv file1 file2 Renames file1 to file2
  • ln -s /path/to/file_name   link_name Creates a symbolic link to file_name
  • touch file_name Creates a new file
  • cat > file_name Places standard input into a file
  • more file_name Outputs the contents of a file
  • head file_name Displays the first 10 lines of a file
  • tail file_name Displays the last 10 lines of a file
  • gpg -c file_name Encrypts a file
  • gpg file_name.gpg Decrypts a file
  • wc Prints the number of bytes, words and lines in a file
  • xargs Executes commands from standard input

File Permission

  • chmod octal filename Change file permissions of the file to octal
  • chmod 777 /data/test.c Set rwx permissions to owner, group and everyone (everyone else who has access to the server)
  • chmod 755 /data/test.c Set rwx to the owner and r_x to group and everyone
  • chmod 766 /data/test.c Sets rwx for owner, rw for group and everyone
  • chown owner user-file Change ownership of the file
  • chown owner-user:owner-group file_name Change owner and group owner of the file
  • chown owner-user:owner-group directory Change owner and group owner of the directory

System

  • uname  Displays  Linux system information
  • uname -r Displays  kernel release information
  • uptime Displays how long the system has been running including load average
  • hostname Shows the system hostname
  • hostname -i Displays the IP address of the system
  • last reboot Shows system reboot history
  • date Displays current system date and time
  • timedatectl Query and change the System clock
  • cal Displays the current calendar month and day
  • w Displays currently  logged in users in the system
  • whoami Displays who you are logged in as
  • finger username Displays information about the user

Search

  • grep ‘pattern’ files Search for a given pattern in files
  • grep -r pattern dir Search recursively for a pattern in a given directory
  • locate file Find all instances of the file
  • find /home/ -name “index” Find file names that begin with ‘index’ in /home folder
  • find /home -size +10000k Find files greater than 10000k in the home folder

Network

  • ip addr show Displays IP addresses and all the network interfaces
  • ip address add 192.168.0.1/24 dev eth0 Assigns IP address 192.168.0.1 to interface eth0
  • ifconfig Displays IP addresses of all network interfaces
  • ping  host ping command sends an ICMP echo request to establish a connection to server / PC
  • whois domain Retrieves more information about a domain name
  • dig domain Retrieves DNS information about the domain
  • dig -x host Performs reverse lookup on a domain
  • host google.com Performs an IP lookup for the domain name
  • hostname -i Displays local IP address
  • wget file_name Downloads a file from an online source
  • netstat -pnltu Displays all active listening ports

Process Related

  • ps Display currently active processes
  • ps aux | grep ‘telnet’ Searches for the id of the process ‘telnet’
  • pmap Displays memory map of processes
  • top  Displays all running processes
  • kill pid Terminates process with a given pid
  • killall proc Kills / Terminates all processes named proc
  • pkill process-name Sends a signal to a process with its name
  • bg Resumes suspended jobs in the background
  • fg Brings suspended jobs to the foreground
  • fg n job n to the foreground
  • 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

For some more great examples check out https://linoxide.com/linux-command/linux-commands-cheat-sheet/

Here is a tutorial for Linux administration, it is 2 hours long but it starts from the beginning and by the end you will be comfortable administering a Linux operating system.

Drop us a message or give us a call

Date: June 29, 2020

Author: Magnetar IT

Inspired to improve your IT? Get in Touch!

Contact Us

Check out our social media: