Most Frequently Used linux – Part 1

This post provides practical examples for frequently used commands in Linux / UNIX systems.

This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common Linux commands. Bookmark this article for your future reference.

The command list is:

  • ls command

Display filesize in human readable format (e.x. MB/GB etc.,)

# ls -lh

-rw-r–r–  1 utilizador  staff   7,9K  2 Set 11:42 known_host

Order Files Based on Last Modified Time (In Reverse Order)

# ls -ltr

 

  • tar command

Create a new tar archive.

# tar cvf archive_name.tar foldername/

Extract from an existing tar archive.

# tar xvf archive_name.tar

 

  • grep command

Search for a given string in a file

# grep -i “Your”  your_file

Print the matched line, along with the 2 lines after it.

# grep -A 2 -i “example1” demo_text

Search for a given string in all files recursively

# grep -r “string” *

 

  • cat command

    You can view/read multiple files at the same time. The following example prints the content of file1 followed by file2 to stdout.

# cat file1 file2

If you want to print the file to stdout line by line you can use cat -n

# cat -n /etc/hosts

 

  • find command

Find files using file-name

# find -iname “my_script.sh”

Execute commands (rm – remove) on files found by the find command

# find -iname “my_script.sh” -exec rm {} \;

 

and for now that’s it.

Check Part 2 for more commands here.

Cheers

No Comments

Post a Comment