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.

 

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

 

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

 

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 inadvertantly delete your whole drive!

ls
ls -ltr
mkdir NewDirectory
rmdir DirectoryName
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/
~$ 
~$ ls -ltr
total 124080
-rwxrwxr-x  1 tim  tim     11384 Feb 10  2014  bin_steamdeps.py
-rw-rw-r--  1 tim  tim  31223808 Mar 26  2018  R8000-back-to-ofw.trx
drwxr-xr-x  2 tim  tim      4096 Sep  3  2018  Templates
drwxr-xr-x  2 tim  tim      4096 Sep  3  2018  Public
mkdir docs
rmdir docs
rm doc.txt
rm doc.*
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