Basic linux commands
Linux

Basic Linux Commands Made Easy Part2

On a previous article, we’ve discussed some Linux commands and we see some of the commands to show files, traverse over directories and make them and much more, Now these were just first level of the basic Linux commands let’s take one more step and see some of the basic Linux commands that you will use for your everyday use.

We talked about ls command in the previous post with only 2 parameters let dig deep and see more parameters that can make you more powerful

we will talk about:

Filtering Output

Creating Files

Linking files

Viewing the file type

Viewing parts of a file

Running Processes

 

 

ls –R to list recursively all files inside the directory

the -R parameter would have continued to traverse those as well. As you can see, for large directory structures this can become quite a large output listing

ls -R command

ls –r  Reverse the sorting order for the displayed files and directories.

ls -r- command

ls –S Sort the output by file size.

ls -lS command

Ls –t Sort the output by file modification time.

ls -lt command

Filtering Output

ls -l myfile?

A question mark to represent one character

ls -l myprob*

An asterisk to represent zero or more characters

The question mark and asterisk are called wild characters

ls wild character

Creating Files

touch test1

the touch command just created an empty file. The touch command can also be used to change the access and modification times on an existing file without changing the file contents

 

touch command

if the file exists it will change the access time if not it will create it

in order to change modification time  just type it with –t followed by the time like the following format YYYYMMDDHHMM

touch -t 202012011200 test1

touch existed file

Linking files

We know from the previous post that cp command is used to copy file

But what about creating a shortcut for that file in a different place that in Linux is called linking files

There are two different types of file links in Linux:

  • hard link
  • symbolic, or soft link

 

cp -l file1 file2

The hard link creates a separate file that contains information about the original file and where to locate it

Keep in mind that you can only create a hard link between files on the same physical drive. You can’t create a hard link between files under separate mount points. In that case, you’ll have to use a soft link

cp hardlink

The -s parameter creates a symbolic or soft link:

cp -s file1 file2

cp softlink

Here we should mention also another command that makes links other than cp which is ln command you can create hard and soft links with it as this

ln myfile myfile2

This command creates hard link

ln command

ln -s myfile myfile2

This command creates soft link

ln softlink

Viewing the file type

file myfile

Determines the kind of the file

file command

Viewing parts of a file

We know also from the previous post the cat and less commands now for another geeky command that you will use a lot really in your daily work

 

The tail command

This command display the last 10 lines of a file

-n parameter to specify the number of lines

-f parameter to stay on the file and continue to watch the last lines you specified like monitoring and this is the very important thing when looking in log files

tail command

 

The head command

This command the same as tail but this command displays the first 10 rows of a file with the same parameters

head command

Running Processes

ps aux

This command is to see the currently running processes

ps aux

 

top command shows the running processes

-c parameter to show the command path which is running

top command

 

kill command to kill a running process

to kill a process

pkill processName

kill command

 

xkill and press Enter to kill any nonresponsive window

xkill command

 

df command (actually this is not quietly of the basic Linux commands but you should know it to see your mounted disks )

disk free space

df –h

-h for human readable value

df command

 

This was for basic Linux Commands second part I hope you enjoy it and wait for another exciting post about Linux commands