Linux Commands Best for Log File Operations

Laiba Nasir
2 min readJan 13, 2023

--

Worldwide, companies use Linux to run servers, appliances, and more because it is so a flexible tool to use to move and work. That is the reason some programmers prefer to use Linux because they feel it gives them more freedom and more security, and definitely more flexibility and power.

Copy log 👥

To copy file

cp source_path destination_path

This command is used to copy a file within any server or from one server to another server

To copy log files from a particular directory to the root file scp command will copy

$ scp filename ~
$ ls -ltrh

or

scp source_path destination_path

Mail File 👟

Here a for attachment and s is used for the subject of the email

$ mailx -a filename -s 'subject of email' email </dev/null

Zip File 🙌

$ zip -r filename.zip filename

The following command is used to zip files in .tar format.

$ tar –cvf tar-filename source-foldername

The following command is used to unzip files of .tar format.

$ tar –xvf filename

Unzip file 🍃

unzip filename.zip

GunZip 😀 ⚡️

To zip a file or unzip a zip file there is gunzip. is not it cool? 🙌

gunzip filename

This option is used to view the text within a compressed file without uncompressing it.

gunzip -c filename.tar.gz

Search in File

it searches the text in the directory recursively

$ grep -r 'text search'

Open File

To open a log file using the command use cat. here | less is used to open the very large file in less

$ cat filename | less

To search the particular text in that file write the forward slash and the word you wanna search.

/search_text

if you want to open the zip file

$ zcat filename

List Files

There are different ways to list files in the directory. The easiest way to list files by name is simply to list them using the ls command. Listing files by name (alphanumeric order) is, after all, the default. You can choose the ls (no details)

$ ls

This command lists all the contents in the current working directory.

ls -l (lots of details) to determine your view.

$ ls -l

Use this option to list files in order of age — how new they are. Add the -r option to get the most recently updated files showing up last in the list. use this alias to show me a list of the files that I’ve most recently updated

$ ls ltrh

History

is a command used to show command line history

$ history

Head

This prints the first 10 lines of any file, or output of any file.

head filename

Tail

The tail command lets us view the tail of the text file as the last 10 lines. The updates are done live so we’ll always see the latest.

tail filename

Curl Command

It can download internet content from one server to another, transfer data mainly, and run apis.

curl  URL

Sort File

--

--