CLI Part 3. Working With The Filesystem

cp - Copy

Copy a file or directory from one location to another.

Example:

$ cp myFile.txt myFile.txt.backup
$ cp -R myFolder myFolderBackup

mv - Move

Move a file from one location to another, or simply rename it.

Example:

$ mv myFile.txt ./myFileStorage/myFile.txt
$ mv myFile.txt myRenamedFile.txt

rm - Remove / Delete

Careful with this one - don't expect to find you beloved work awaiting you in the trash. This will instantly remove a given folder or file.

Example:

$ rm myUnwantedFile.txt
$ rm -R myUnwantedDirectory
$ rm -Rf myUnwantedDirecory_DontEvenAskMe
$ find . -name *.jpg -exec rm -f {} \;

mkdir - Make a Directory

Simple, mill make one or more directories, individually, or complete structure.

Example:

$ mkdir myNewDirectory
$ mkdir dir_1 dir_2 dir_3
$ mkdir -p my/new/directory/structure

touch - Update a File

Time-stamps the file with the current time. Another handy use for touch is its ability to create new files.

Example:

$ touch myFile.txt
$ touch newFile1.txt newFile2.txt

more - Show me nicely

I'll throw it into this section since I seem to mostly use it with reading files. more is a tool to neatly render text to screen. So instead of seeing 2000 lines wizz over your terminal, you can move through, screen by screen, or line by line.

Don't forget that more isn't limited to displaying file content, it's also great for managing output from other commands (see the second example below).

Example:

$ more myFile.txt
$ ls myVeryLargeDirectory | more

Since more is an active tool, you get key commands here are some of the basics:

  • space scroll forward one window
  • return scroll forward one line
  • b scroll back one window
  • y scroll back ones line
  • q exit the more interface
  • / then your search term to find a string (example "/findMe")

ln - Linking

Link files and Directories.

Example:

$ ln -sfl myDocuments/work/proposals/2007 currentProposals

Comments:

Leave a comment