Skip to main content

Commands used for File Handling

LS

The command “ls” displays the list of all directories, folder, and files present in the current directory.

 

LS - LTR

The above-mentioned command displays the name of directories, folders, files with their respective owner name, group’s name, and rights your user has over these.

 

 

 

ls
ls -ltr
 

MKDIR

The command “mkdir” allows users to create directories/folders in the system. The user running this command must have suitable rights over the parent directory to create a directory or they will receive an error.
Syntax: mkdir New_Directory’s_Name

 
mkdir NewDirectory
 

RMDIR

The command “rmdir” allows users to remove directories/folders from the system. The user running this command must have suitable rights over the parent directory to remove a directory AND the directory must not have any files or sub-directories within it or you  will receive an error.
Syntax: rmdir Directory’s_Name

rmdir DirectoryName

RM

The command “rm” is used to remove files from a directory.

 

RM -RF

Permanently deletes the specified directory and ALL files and sub-directories beneath the specified directory.

Be VERY careful using this command as you can inadvertently delete your whole drive!

rm filename

 

  

rm -rf /path/to/dir/name

 

 

 

 

 

~/docs$ ls
docs2  doc.txt
~/docs$ cd ..
~$ rmdir docs
rmdir: failed to remove 'docs': Directory not empty
~$ rm -rf /home/tim/docs/
~$ 






TOUCH

Creates an empty file at the specified path with the specified name.

Useful for creating a blank file you intend to edit with a CLI editor, such as VIM or NANO.

touch /path/name/filename.ext
~$ ls doc.txt
ls: cannot access 'doc.txt': No such file or directory
~$ touch /home/tim/doc.txt
~$ ls doc.txt
doc.txt