Basic Commands: Difference between revisions

Line 321: Line 321:


To display all available signals:
To display all available signals:
kill -l


kill -l
To kill the PID 257:
To kill the PID 257:
kill 257


kill 257
==ping Command==
31. ping Command
Use the ping, also known as the Packet Internet Groper, command to check network connectivity between two computers. You can use this command to troubleshoot connectivity, name resolution, and reachability. It accepts an IP address or an URL as an input.
Use the ping, also known as the Packet Internet Groper, command to check network connectivity between two computers. You can use this command to troubleshoot connectivity, name resolution, and reachability. It accepts an IP address or an URL as an input.


To check network connectivity to 172.168.1.1 IP address and send 5 data packets:
To check network connectivity to 172.168.1.1 IP address and send 5 data packets:
ping -c 5 172.168.1.1


ping -c 5 172.168.1.1
==vi and nano Command==
32. vi and nano Command
Use the vi and nano commands to create a new file, read a file, or edit an existing file. Vi is the default text editor for several Linux distributions and it is very simple to use. Nano is a terminal-based text editor that is ideal for making some changes to any files or creating basic plain text files.
Use the vi and nano commands to create a new file, read a file, or edit an existing file. Vi is the default text editor for several Linux distributions and it is very simple to use. Nano is a terminal-based text editor that is ideal for making some changes to any files or creating basic plain text files.


To open the existing file or to create a new file:
To open the existing file or to create a new file:
 
vi updates.txt
vi updates.txt
or
or
nano filename.txt
nano filename.txt
33. history Command
==history Command==
Use the history command to view the history of all the previously executed terminal commands that you run. The maximum number of entries that BASH should store can be defined in your .bashrc file. Linux commands that you execute are considered events and every event is associated with an event number. You can recall, remove, or change commands using their event numbers.
Use the history command to view the history of all the previously executed terminal commands that you run. The maximum number of entries that BASH should store can be defined in your .bashrc file. Linux commands that you execute are considered events and every event is associated with an event number. You can recall, remove, or change commands using their event numbers.


To list the last 5 commands, including itself:
To list the last 5 commands, including itself:
history 5


history 5
To remove the history of event number 1525:
To remove the history of event number 1525:
history -d 1525


history -d 1525
Note: history command behavior may change depending on the shell you are being used.
Note: history command behavior may change depending on the shell you are being used.


34. passwd Command
==passwd Command==
Use the passwd command to change the user account password. A normal user can change only their own password, but the root user or user with sudo privileges can change the password of any user account. This command can also be used to delete or expire an account password.
Use the passwd command to change the user account password. A normal user can change only their own password, but the root user or user with sudo privileges can change the password of any user account. This command can also be used to delete or expire an account password.


To change the password for the user bob:
To change the password for the user bob:
sudo passwd bob


sudo passwd bob
==which Command==
35. which Command
Use the which command to locate the executable file of the specified command. This command searches for the executable file location in the $PATH environment variable. The which command returns any of the following status:
Use the which command to locate the executable file of the specified command. This command searches for the executable file location in the $PATH environment variable. The which command returns any of the following status:


To display executable file locations for useradd command, type:
To display executable file locations for useradd command, type:
which useradd /usr/sbin/useradd


which useradd /usr/sbin/useradd
==less Command==
36. less Command
Use the less command to view the contents of a file one screen at a time, starting at the beginning. This command provides the capability of both backward and forward navigation. The less command has quick file access because it does not access the entire file if the file is large.
Use the less command to view the contents of a file one screen at a time, starting at the beginning. This command provides the capability of both backward and forward navigation. The less command has quick file access because it does not access the entire file if the file is large.


To display the contents of the updates.txt file one screen at a time.
To display the contents of the updates.txt file one screen at a time.
less updates.txt


less updates.txt
==tail Command==
37. tail Command
Use the tail command to view the contents of a file, starting at the bottom. By default, it displays the last 10 lines of the file, but you can change this default behavior. The tail command can also be used to monitor the file. When you add new lines to the file, then the display is updated.
Use the tail command to view the contents of a file, starting at the bottom. By default, it displays the last 10 lines of the file, but you can change this default behavior. The tail command can also be used to monitor the file. When you add new lines to the file, then the display is updated.


To display the last 10 lines of the file updates.txt:
To display the last 10 lines of the file updates.txt:
tail updates.txt


tail updates.txt
To display the last 15 lines of the file access.log:
To display the last 15 lines of the file access.log:
tail -n 15 access.log


tail -n 15 access.log
==head Command==
38. head Command
Use the head command to display the contents of a file, starting at the beginning. By default, it displays the first 10 lines of the file, but you can change this default behavior.
Use the head command to display the contents of a file, starting at the beginning. By default, it displays the first 10 lines of the file, but you can change this default behavior.


To display the first 10 lines of the file updates.txt:
To display the first 10 lines of the file updates.txt:
head updates.txt


head updates.txt
==grep Command==
39. grep Command
Use the grep, also known as global regular expression print, the command to search for a word or string of characters in a file or directory. The search pattern is termed regular expression. When the grep command finds a matching string in the file, then this command prints the line that contains the string.
Use the grep, also known as global regular expression print, the command to search for a word or string of characters in a file or directory. The search pattern is termed regular expression. When the grep command finds a matching string in the file, then this command prints the line that contains the string.


To search for the string 'welcome' in the file log.txt:
To search for the string 'welcome' in the file log.txt:
grep welcome log.txt


grep welcome log.txt
==diff Command==
40. diff Command
Use the diff command to do a line-by-line comparison of two files and display their differences. You can also use this command to compare the contents of Linux directories.
Use the diff command to do a line-by-line comparison of two files and display their differences. You can also use this command to compare the contents of Linux directories.


To show differences between two files named source.java and newsource.java, type
To show differences between two files named source.java and newsource.java, type
diff /dir1/source.java /dir2/newsource.java


diff /dir1/source.java /dir2/newsource.java
To show differences between Documents and Docs directories.
To show differences between Documents and Docs directories.
diff Documents/ Docs


diff Documents/ Docs
==find Command==
41. find Command
Use the find command to search and locate the files and directories that match the specified conditions. This command enables you to search using file or folder name, creation date, modification date, permissions, and owner.
Use the find command to search and locate the files and directories that match the specified conditions. This command enables you to search using file or folder name, creation date, modification date, permissions, and owner.


To search the file named program.py in the /home/linuxopsys/projects directory, type:
To search the file named program.py in the /home/linuxopsys/projects directory, type:
find /home/linuxopsys/projects -type f -name program.py


find /home/linuxopsys/projects -type f -name program.py
To search for files with given permissions in the current directory:
To search for files with given permissions in the current directory:
find . -perm 664


find . -perm 664
==echo Command==
42. echo Command
Use the echo command to display the specified text or string on the terminal. This command is most commonly used in batch files and scripting languages to display standard text output. You can also use this command to display the values of an environment variable.
Use the echo command to display the specified text or string on the terminal. This command is most commonly used in batch files and scripting languages to display standard text output. You can also use this command to display the values of an environment variable.


To print the string “This is a sample string” on the terminal:
To print the string “This is a sample string” on the terminal:
echo "This is a sample string"


echo "This is a sample string"
This is a sample string
This is a sample string
To print the value of the PATH environment variable:
To print the value of the PATH environment variable:
echo $PATH


echo $PATH
Output:
Output:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin


/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
==shutdown, reboot Command==
43. shutdown, reboot Command
Use the shutdown command to gracefully and securely shut down your Linux computer.
Use the shutdown command to gracefully and securely shut down your Linux computer.


Line 427: Line 427:


To restart your system after 5 minutes:
To restart your system after 5 minutes:
shutdown -r +5


shutdown -r +5
To immediately restart your computer:
To immediately restart your computer:
reboot


reboot
==Alias==
44. Alias
The Alias command allows you to define temporary aliases for current sessions. It allows you to execute one or more commands.
The Alias command allows you to define temporary aliases for current sessions. It allows you to execute one or more commands.


Create a new alias named 'lsall', type:
Create a new alias named 'lsall', type:
alais lsall="ls -a"


alais lsall="ls -a"
Lists all aliases for the current session:
Lists all aliases for the current session:
alias


alias
Note: Alias behavior may change depending on the shell you are being used. It is traditionally used in bash shell.
Note: Alias behavior may change depending on the shell you are being used. It is traditionally used in bash shell.


45. exit
==exit==
The exit command ends a shell session and closes the terminal you are using
The exit command ends a shell session and closes the terminal you are using
exit


exit
==wget command==
46. wget command
The wget command is used to retrieve or download content from the internet.
The wget command is used to retrieve or download content from the internet.


To download WordPress using wget, type:
To download WordPress using wget, type:
wget https://wordpress.org/latest.tar.gz


wget https://wordpress.org/latest.tar.gz
The latest.tar.gz file will be downloaded to the current directory.
The latest.tar.gz file will be downloaded to the current directory.


47. clear command
==clear command==
The clear command is used in Linux to clear the terminal screen. This is similar to cls command in other operating systems.
The clear command is used in Linux to clear the terminal screen. This is similar to cls command in other operating systems.
 
clear
clear


==Source==
==Source==
*[https://linuxopsys.com/topics/basic-linux-commands linuxopsys.com]
*[https://linuxopsys.com/topics/basic-linux-commands linuxopsys.com]