File Management in the Terminal

Copying files and directories

  • cp manual Duplicate an entire directory including subfolders cp -r SRC DEST
  • Create a symbolic link to a file cp -s FILE NEWLINK (equivalent to ln -s FILE NEWLINK)
  • Create a hard link to a file cp -l FILE NEWLINK (equivalent to ln FILE NEWLINK)

Getting information

  • stat manual Print last access time, modify time etc. stat FILE
  • du manualShow summary size of a directory in human language du -sh DIR
    • Exclude certain files --exclude=’*.o’ (pattern is a shell pattern)
  • find manual Count files in a directory find DIR -type f | wc -l (or use ncdu)

Looking in files

  • cat manual Number the lines in a file cat -n FILE
    • nl manual A more sophisticated version of the above nl file
  • head manual Show first N lines of a file head -3 FILE
  • tail manual Show last N lines of a file tail -3 FILE
  • Follow modifications to a file and finish when the process terminates tail –pid=PID -f FILE

Manage permissions and owners

Misc

  • xdg-open manual Open any file from the command line in its associated program xdg-open FILE
comments powered by Disqus