Basic Linux Commands

Basic Linux Commands

Cheatsheet for some important commands...

Introduction -

In the recent few weeks, I have started using Linux on a daily basis. As we all know, someone using Linux needs to have a good grasp on the commands. Hence, I thought of preparing something similar to a cheatsheet for some of the most used commands -

FILE & DIRECTORIES -

  1. ls - directory listing (list all files/folders on current dir)
  2. ls -l - formatted listing
  3. ls -la - formatted listing including hidden files
  4. cd dir - change directory to dir (dir will be directory name)
  5. cd .. - change to the parent directory
  6. cd ../dir - change to dir in the parent directory
  7. cd - change to the home directory
  8. pwd - show current directory
  9. mkdir dir - create a directory dir
  10. rm file - delete a file
  11. rm -f dir - force remove the file
  12. rm-r dir - delete directory dir
  13. rm-rf dir - remove directory dir
  14. cp file1 file2 - copy file1 to file2
  15. mv file1 file2 - rename file1 to file2
  16. mv file1 dir/file2 - move file1 to dir as file2
  17. touch file - create or update file
  18. cat file - output contents of the file
  19. cat > file - write standard input into the file
  20. cat >> file - append standard input into the file
  21. tail -f file - output contents of the file as it grows

NETWORKING -

  1. ping host - ping the server
  2. who is domain - get whois for domain
  3. dig domain - get DNS for domain
  4. dig -x host - reserve lookup host
  5. wget file - download file
  6. wget -c file - continue stopped download
  7. wget -r url - recursively download files from url
  8. curl url - outputs the webpage from url
  9. curl -o meh.html url - writes the page to meh.html
  10. ssh user@host - connect to host as user
  11. ssh -p port user@host - connect using port
  12. ssh -D user@host - connect & use bind port

PROCESSES -

  1. ps- display currently active processes
  2. ps aux - detailed outputs
  3. kill pid - kill process with process id (pid)
  4. killall proc - kill all processes named proc

SYSTEM INFO -

  1. date - show current date/time
  2. uptime- show uptime
  3. whoami - who you're logged in as
  4. w- display who is online
  5. cat /proc/cpuinfo - display CPU info
  6. cat /proc/meminfo - memory info
  7. free- show memory and swap usage
  8. du- show directory space usage
  9. du -sh - displays readable sizes in GB
  10. df - show disk usage
  11. uname -a - show kernel config

COMPRESSING -

  1. tar cf file.tar files - tar files into file.tar
  2. tar xf file.tar - untar into the current directory
  3. tar tf file.tar - show contents of the archive
    options:
    c - create an archive
    t - table of contents
    x - extract
    z - use zip/gzip
    f - specify the filename
    j - bzip2 compression
    w - ask for confirmation
    k - do not overwrite
    T - files from the file
    v - verbose

PERMISSIONS -

chmod octal file - change permissions of file
4 - read (r)
2 - write (w)
1 - execute (x)

order: owner/group/world

chmod 777 - rwx for everyone
chmod 555 - rw for owner / rx for group

SOME OTHERS -

  1. grep pattern files - search in files for pattern
  2. grep -r pattern dir - search for pattern recursively in dir
  3. locate file - find all instances of file
  4. whereis app - show possible location of app
  5. man command - show manual page for command