Basic Unix commands-2

 6. ls command

Syntax ls [options]

Description:

-a    shows all file including hidden files
-d    If an argument is a directory it only lists its name not its contents
-p    displays a slash(/) in front of all directories
-r    reverses the order of how the files are displayed
tkanu025@hp:~$ ls
avengers ff-series insta oop os
tkanu025@hp:~$ ls -p
avengers/ ff-series/ insta/ oop/ os/
tkanu025@hp:~$ ls -r
os oop insta ff-series avengers
tkanu025@hp:~$ ls -A
.bash_history .bash_logout .bashrc .landscape .motd_shown .profile avengers ff-series insta oop os
tkanu025@hp:~$ ls -a
. .. .bash_history .bash_logout .bashrc .landscape .motd_shown .profile avengers ff-series insta oop os
tkanu025@hp:~$ ls ff-series -d
ff-series
tkanu025@hp:~$ ls ff-series
ff6 ff7 ff9
tkanu025@hp:~$
view raw ls.sh hosted with ❤ by GitHub

Output

7. Echo command

It prints the given input string to standard output.(It is same as printf("") in c programming language).

syntax: eco 'string'

tkanu025@hp:~$ echo "hello to the world of Linux"
hello to the world of Linux
tkanu025@hp:~$ echo 'this is echo command'
this is echo command
tkanu025@hp:~$
view raw echo.sh hosted with ❤ by GitHub

output

8. mkdir command

This command is used to create a new repository

Syntax: mkdir [options] [directory name]

All options can be used as per requirements
directory name is the mane of the folder which you want to create
-m    set permission mode (as in chmode)
-p    No error if existing, make parent directories as needed.
-v    Print a message for each created directory
tkanu025@hp:~$ ls
avengers ff-series insta oop os
tkanu025@hp:~$ mkdir Bond007
tkanu025@hp:~$ ls
Bond007 avengers ff-series insta oop os
tkanu025@hp:~$
view raw mkdir.sh hosted with ❤ by GitHub

9. rmdir command

Description:
It is used to delete a directory and its subdirectories.
it only removes empty directory.
 
Syntax: rmdir [options] [directory name]
tkanu025@hp:~$ ls
Bond007 avengers ff-series insta oop os
tkanu025@hp:~$ rmdir os
tkanu025@hp:~$ ls
Bond007 avengers ff-series insta oop
tkanu025@hp:~$ rmdir insta
rmdir: failed to remove 'insta': Directory not empty
tkanu025@hp:~$
view raw rmdir.sh hosted with ❤ by GitHub

10. rm command

It is used to remove the file from the directory.
Note: the rmdir is to delete folder where as rm is to delete files

Syntax: rm [options] [file name]

Description:

  • Deleted file can't be recovered.
  • rm can't delete the directory.
  • All files can be deleted at once just by using * (asterisk). i.e., rm *
-f    ignore non-existent files, and never prompt before removing.
-i    Asks for confirmation before every removal

tkanu025@hp:~$ ls
1 Bond007 avengers commands.txt ff-series filename.txt insta main.py oop oop.java
tkanu025@hp:~$ rm filename.txt
tkanu025@hp:~$ ls
1 Bond007 avengers commands.txt ff-series insta main.py oop oop.java
tkanu025@hp:~$ rm 1
rm: cannot remove '1': Is a directory
tkanu025@hp:~$ rm -i commands.txt
rm: remove regular empty file 'commands.txt'? y
tkanu025@hp:~$ ls
1 Bond007 avengers ff-series insta main.py oop oop.java
tkanu025@hp:~$ rm -f oop.java
tkanu025@hp:~$ ls
1 Bond007 avengers ff-series insta main.py oop
tkanu025@hp:~$
view raw rm.sh hosted with ❤ by GitHub

Previous Page        Next Page

Comments

YouTube

Popular posts from this blog

GTU OOP Program - 17 tic-tac-toe

GTU OS Program - 11 Filters

GTU OS Program - 8