20 Basic linux commands for kids – part 2

This is the 2 part of linux commands where I covered the next 20 commands continuing the part 1. If you haven’t gone through part 1 of the linux commands I suggest you complete the part 1 first before this by clicking the button.

1.diff

diff will output the difference between two files by comparing them line by line

syntax: diff [file1_name] [file2_name]

2.find

find is used to find the files with specific pattern or all in the present dir. this command is mostly used with the option -name which searches files by name

syntax: find . -name ‘*l.txt’ (finds all the files with the pattern matching in quote)

3.grep

grep is the most popular command in linux . It can used for search in files. Syntax: grep “text” file_name We can also use grep if you are not sure of file where it located by using the below syntax:

grep -r “hello” .

4.du

“du” command will return the size of directorys and files in the present working directory. to get du in human readable format just use -h

5.df

“df” is used to get disk usage information . to get in human readable fromat use “df -h”

6.history

“history” display’s the history of commands used in the shell with the numbers before the command

7.ps

“ps” display the information about currently running processes . we can also see all the processes (including system processes ) by using the command “ps ax”

8.top

“top” command display the dynamic real time information about running processes in the system . by default it shows top most cpu intensive processes.

9.kill

Linux processes can receive signals and react to them . The kill program can send a variety of signals to a program other than terminate a program. If the process is still running after the below Syntax you can force kill using the signal -9 “kill -9 [pid]”

Syntax: kill [pid]

10.killall

similar to the kill command but using killall we can send signal to multiple processes at once. you can also use killall to kill all the process with a same name. i.e; if you have 2 node servers running in the background you can use the following to kill all the processes with the name node syntax : killall node

11.jobs,bg and fg

jobs will list the active jobs,bg is used to send a process into background and fg will convert a background process to foreground

Syntax: bg [job_id] -> to set a process into background Syntax: fg[job_id] -> to set a background process into foreground Syntax: jobs -> to list all the process Note: to end a foreground process use “ctrl+c” and to pause use “ctrl+z”

12.nano

nano is a text editor like vim but nano is much simpler and easy to use for beginners . if you want’ to quit from nano use “ctrl+x”. and to save use “ctrl+s”.

syntax: nano [file_name]

13.alias

If you ever has a command that you use frequently but it is too long to type or remember you can make use of alias where you can name that long command into your own little command by using the below syntax: alias [alternative_name]=’ls -al’

but the problem here is when ever you restart the PC the alternative command won’t work . so, to avoid this you need to save the above statement in a file called “.bashrc” . which is located in your user home directory . Note: in “.bashrc” file there are already a few alias statements you can add your’s at the end of that statements

14.xargs

using xargs the output of a command is used as the input of another command. Syntax: command1 | xargs command2

15.ln(links)

There are two types of links 1)hard link 2) soft link 1)Hard links are not much used and the syntax used to create a hard links is: ln [original_file] [hard_link_file_you_want_to_get] Change in original file or hard_link file will change the both the files and if you delete the hard_link file there still will be original file remains same and vice-versa . In hard_link both the original file and hard_link file point to the same Memory location . so, even one file deleted other file will not loose it contents

2)To create a soft link use the following syntax: ln -s [original_file] [softlink_file] similar to hard link if you even change the either original file or soft_link file changes are made to both.

In soft_link , the soft_link file points to the original file and original file will point to the memory location.so, losing of original file will make soft_link file no use.

16.who

The who command displays the users logged in to the system. This command is used when you are using a server multiple people have access to .

Note: don’t confuse this with “whoami” which is used to get the username

17.su(switch user)

using “su” you can switch between users syntax: su [user_name] and you need to enter the password for the given user_name

18.sudo

sudo is commonly used to run a command as a root user. Generally it asks for your password to conformation after running the sudo command if your username is registered as administrator.

19.passwd

User’s in linux hava a password assigned . and you can change it using the “passwd” command.

20.chmod

“chmod” changes the access permissions,or modes of the specified file or directory. Modes can determine who can read, write and execute Note: chmod can be used only by the file owner

To give permissions to user use –> chmod u+rwx [file_name] (give all permissions to user) To give permissions to group use –> chmod g+rw [file_name] (gives read and write permissions to group) To give permissions to others use –> chomod o-rwx [file_name] (removes all permissions to others)