Skip to content

1.4 File and Directory Commands

Tomato6966 edited this page Jun 29, 2021 · 1 revision

List all files in a long listing (detailed) format

ls -al

Display the present working directory

pwd

Create a directory

mkdir directory

Remove (delete) file

rm file

Remove the directory and its contents recursively

rm -r directory

Force removal of file without prompting for confirmation

rm -f file

Forcefully remove directory recursively

rm -rf directory

Copy file1 to file2

cp file1 file2

Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents

of source_directory.
cp -r source_directory destination

Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2

mv file1 file2

Create symbolic link to linkname

ln -s /path/to/file linkname

Create an empty file or update the access and modification times of file.

touch file

View the contents of file

cat file

Browse through a text file

less file

Display the first 10 lines of file

head file

Display the last 10 lines of file

tail file

Display the last 10 lines of file and "follow" the file as it grows.

tail -f file
Clone this wiki locally