Copy, move, remove, rename, view

Copying Files

$ cp file1 file2

copies file1 in the current working directory into file2. It file2 exists, its content would be replaced. If it doesn't exist, it will be created.

Moving or renaming files

$ mv file1 file2

moves or renames file1 to file2

Removing files and directories

$ rm file1

removes file1

$ rmdir dir1

removes dir1 if it is empty

To remove a directory and all it contents use

$ rm -r dir1

Be sure that you want to remove a file before running the rm or rmdir command. The deleted files and directories cannot be recovered.

Displaying the contents of a file on the screen

$ clear

clears the screen

$ cat file1

displays file content on the screen. The content is not scrollable in the terminal but usually scrollable with the ternimal window.

$ less file1

displays file content, one page a time. Press the [space-bar] to see the next page, and type [q] to quit reading.

$ head file1

writes the first few lines of the file content on the screen.

$ head -25 file1

writes the first 25 lines of the file content on the screen.

$ tail -10 file1

writes the last 10 lines of the file content on the screen.

Command Summary

Command Meaning
cp file1 file2 copy file1 to file2
mv file1 file2 move or rename file1 to file2
rm file remove a file
rmdir directory remove a directory
cat file display a file
less file display file one page at a time
head file display the first few lines of file
tail file display the last few lines of a file