DEV Community

sanadiqbal
sanadiqbal

Posted on

Some Important CLI commands

IMPORTANT CLI COMMANDS AND THEIR USES

Some of the most commonly used CLI commands :

  1. more :more command is used to view large text files one page at a time.User can scroll up and down through the text using this command.

Syntax
more [ options] -filename

Options
-m : It limits the line displayed in a single page.
-d : displays user message at right corner.
-s :Squeezes blank line.
+/string_name :To find a given string.
+num: To display contents from a specific line.

more can also be used using pipes:

cat filename | more
Enter fullscreen mode Exit fullscreen mode
  • tail : tail is used to print the last n lines of the given file.

Syntax
tail -[ number of lines] file_name

tail -10 hpt.txt
Enter fullscreen mode Exit fullscreen mode
  • rsync : rsync is used to sync files between two hosts or machines.

Syntax
rsync [ option ] source [ destination ]
Options
-a : Archive mode includes all necessary options like copying file recursively.
-v : Gives a brief information about files being transferred and the gives brief summary of data transferred at the end.
-h : Outputs in a human readable format.
-z : Compresses file data during transfer.

  • grep: grep is used to search the file for a particular string.

Syntax
grep [ option ] string_to_be searched filename
Some of the options
-c : prints the count of lines matching the given string
-h : Displays the matched lines only not the file name.
-i :Ignores the cases
-l :Displays file name list only
-n :Display the matched lines and their number.
-v :Prints all the line that don't match the given string.

grep -c ball a.txt
Enter fullscreen mode Exit fullscreen mode
  • find: find command is used to find files and directories. Syntax find [ where to find ] [ options ] [ what to find]

Options
-name : Searches the file for a given name.
-user : Search the file with given user name.
-perm : Searches the file for a given file permission.

find ~ -name abc.txt
Enter fullscreen mode Exit fullscreen mode

We can also use wild card characters if we only know the partial file name.* is used to for more than one character.

Example:

find . -name  *java*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)