Common Linux filesystem commands

https://explainshell.com/ is an excellent resource for explaining what Shell commands do but below are some more basic ones.

  • ls -l
    • -l lists out details of the file such as size & creation date.
  • cd
    • Change directory
      • “cd ..” go up one folder level
      • “cd /folder/” Go directly to folder.
  • mkdir
    • Make a folder
  • cp
    • Copy file/folder.
    • “cp /folder/file1.txt /folder/subfolder/file1.txt” copies the file from one location to another.
  • mv
    • Move file/folder works the same way as cp.
  • rm
    • Remove a file
  • rmdir
    • Remove a folder
  • df -h
    • Reports the space left in the file system
  • grep
    • Provides robust search functionality
    • The grep command is case sensitive; it distinguishes between Science and science.
    • To ignore upper/lower case distinctions, use the -i option, i.e. type % grep -i science science.txt
    • To search for a phrase or pattern, you must enclose it in single quotes (the apostrophe symbol). For example to search for spinning top, type % grep -i ‘spinning top’ science.txt
    • Some of the other options of grep are:
      • -v display those lines that do NOT match
      • -n precede each matching line with the line number
      • -c print only the total count of matched lines
      • Link them like this: % grep -ivn ‘spinning top’ science.txt
  • find
    • This searches through the directories for files and directories with a given name, date, size, or any other attribute you care to specify. To search for all files with the extension .txt, starting at the current directory (.) and working through all sub-directories, then printing the name of the file to the screen, type
      • % find . -name “*.txt” -print
    • To find files over 1Mb in size, and display the result as a long listing, type
      • % find . -size +1M -ls

Leave a Reply