Basic Linux Commands

Linux Cheatsheet

Files and Navigating

  • ls - directory listing (list all files/folders of dir)
  • ls -l - formatted listing
  • ls -la - formatted listing including hidden files
  • cd dir - change directory to dir
  • cd .. - change to parrent directory
  • cd ../dir - change directory to parent dir
  • cd - change to home directory
  • pwd - show current directory
  • mkdir dir - create a directory dir
  • rm file - delete file
  • rm -rf dir - recursive remove directory and content
  • rm -rf / - don't do that!
  • cp file1 file2 - copy file1 to file2
  • mv file1 file2 - move file1 to file2
  • touch file - create or update file
  • cat file - output content of file
  • cat > file - write standard input into file
  • cat >> file - append standard input into file
  • tail -f file - output content of file as it grows

Networking

  • ping target - ping target hostname/ip
  • whois domain - get whois for domain
  • dig domain - get DNS for domain
  • dig -x host - reverse lookup host
  • wget file - download file
  • wget -c file - continue stopped download
  • wget -r url - recursivelly download files from url
  • curl url - outputs webpage from url
  • curl -o site.html url - write the page to site.html
  • ssh use@host - connet to host as user
  • ssh -p port user@host - connect using port
  • ssh -D user@host - connect and use bind port

Processes

  • ps - display currently active processes
  • ps aux - detailed outputs
  • kill pid - kill process with process id (pid)
  • killall proc - kill all processes named proc

System Info

  • date - show current date/time
  • uptime - show uptime
  • whoami - who you're logged in as
  • w - display who is online
  • cat /proc/cpuinfo - display cpu information
  • cat /proc/meminfo - memory information
  • free - show memory and swap usage
  • du - show directory space usage
  • du -sh - display readable sizes in GB
  • df - show disk usage
  • uname -a - show kernel config

Compressing

  • tar cf file.tar files - tar files into file.tar
  • tar xf file.tar - untar into current directory
  • tar tf file.tar - show content of archive

Options:

  • c - create archive
  • t - table of contents
  • x - extract
  • z - use zip/gzip
  • f - specify filename
  • j - bzip2 compression
  • w - ask for confirmation
  • k - do not overwrite
  • T - files from file
  • v - verbose

Permissions

  • chmod actual file - change permissions of file

Options:

  • 4 - read (r)
  • 2 - write (w)
  • 1 - execute (x)

order: owner/group/public


chmod 777 = rwx for everyone

chmod 755 = rw for ownerm rx for group and publicly

Some Others

  • grep pattern files - search in files for pattern
  • grep -r pattern dir - recursive pattern search in dir
  • locate file - find all instances of file
  • whereis app - show possible locations of app
  • man command - show manual page for command
Lastest update April 2019.