Linux Basic Terminal Command Reference

May 21, 2019

The terminal is the Linux command line environment. If you are now in the graphical environment, the simplest way to bring the terminal is to use the Ctr + Alt + T keys, which is supported in all distributions.

There are other ways to do this, like using the Ctr + Alt + F6 keys (to exit the Ctrl + Alt + F7 keys), which brings you the core of the command line.

In this article, I intend to categorize the terminal commands used for most distributions, along with an explanation and example.

For better use of keyboard keys, you can use the shortcut keys in the terminal.

system information

date – Displays the current date and time.
cal shows the calendar for months.
uptime – shows the system’s power on and active users.
w – Show current users who use the system with explanations about their use. The command contains the output information of the uptime command as well.

whoami – The current user that you are currently working with using the system.
finger user – Provides information about the user’s user (instead of the user’s name).
uname – The name of your Unix system, which is the same as Linux.
uname -a – The uname command with the switch a shows the additional information of your operating system, including the kernel version of Linux.
cat / proc / cpuinfo – Displays processor information (CPU).
cat / proc / meminfo – Displays the main memory information (RAM).
df – Displays the amount of memory usage.
du – The amount of space used by all directories
free – displays empty and used RAM and swap memory

 

File commands

ls – Get the list of contents of the current path including folders and files.
the ls -l – The ls command, along with the switch, displays the list of contents of the current path with full information.
ls -laC is the same as the ls -l command, but displays the information as a column.
the ls -F – The f switch in the ls command displays the contents list with the file format.
ls -al – The a switch in the ls command lists the files with hidden files. (The hidden file and folder in Linux have a dot before their name)
cd dir – Redirect the current path to the desired directory (Insert dir instead of dir)
cd – Returns the current path to the main path. (The main path for each user is different, with personal folders and settings there).
mkdir dir – Create a directory (instead of dir write the folder name you want to create).
pwd shows the current path.
rm name – Delete (delete) the desired file or directory (instead of the name the file or folder name is written).
type rm -r dir – Delete a directory with the contents inside it (instead of dir write the folder name).
rm -f file – Force to delete a file for cases where the file is not removed for some reason (the file name is written instead of the file).
type rm -rf dir – Forcing to delete a directory when it is not deleted for some reason (the folder name is written instead of dir).
cp file1 file2 – Copy the file to another path (file1 is the name and path of the source file and file2 the name and path of the destination file).
cp -r dir1 dir2 – Copy the folder to another path (dir1 is the name and path of the source folder and dir2 is the name and path of the destination folder).
a cp file dir – Copy the file to another path with the same name (file name file and dir path of the destination folder).
mv file dir – Move (for example, cut the file in another path with the same name (file name of the file and dir is the path to the destination folder).
mv file1 file2 – Move the file to another path (file1 the name and path of the file and file2 the name and path of the file at the destination).
ln -s file link – build the symbolic link from the file in the desired path (file name and path of the file or folder and link name and link path).
touch file – build a file.
cat> file – Write the text in the file.
cat file – Displays the contents of a file or calls it.
more file – Displays the contents of the file in a small amount (for files with large contents).
command | more – View the output of the command shortly.
less file – Displays the contents of the file as a page to page (for files with large contents).
command | less – Displays the output of the command as a page to the page.
head file – Displays 10 first lines of the contents of a file
head -20 file – Displays the first 20 lines of the contents of a file
tail file – Displays the 10th line of the contents of a file
tail -20 file – Displays the last 20 lines of the contents of a file

File License

chmod octal file – Change the permissions of a file using the access code
Permission specifies a file’s access level file. The access level can be read (number 4), write (number 2), and run (number 1) that the access level of a file is obtained by aggregating these numbers. The access level 7 includes all the materials.
Each access file is defined for three rout, group, and public categories that use the numerical method, and these three sets together the level of access to a file. See the following examples.
chmod 777 file – Allows read, write, and execute files in three categories: root, group, and public.
chmod 755 file – Read, write, and run permissions for root user and read and run permissions for general and group users.

Compression

By default, Linux uses compression in tar format that also supports commands to work with it. Linux uses the Gzip compressor to work with zip compressed tar.gz and gz compressed Bzip2 files for compressed files in tar.bz2 format.

  1. the tar cf file.tar files- Create a tar named file.tar containing files
  2. th tar xf file.tar – Extract the contents of the compressed file.
  3. the tar czf file.tar.gz files – Make a compressed file in tar.gz format from files by Gzip compressor.
  4. Type tar xzf file.tar.gz – Extract the compressed file contents in tar.gz format by Gzip compressor.
  5. Typ  tar czf file.gz files – Generate gz compressed files from files by Gzip compressor.
  6. Type  tar xzf file.gz – Extract the compressed file contents of gz format by Gzip compressor.
  7. tar cjf file.tar.bz2 – Making a compressed file in tar.bz2 format from files by compressor.
  8. tar xjf file.tar.bz2 – Extract the contents of the compressed file in tar.bz2 format by the Bzip2 compressor.

Search

Write grep pattern files – Search the expression in the desired file.
Write  grep pattern dir – search terms in files in the desired directory.
Writ  grep -r pattern dir – The search terms in the files in the desired directory are recursive.
command | grep pattern – Search the expression in the command output.
locate file – Find our desired file in the current path.
find dir -name filename – Find our desired file in the desired directory.
find “_filename_” – Search all files whose names contain the name of the file we are looking for (in the current path).
updatedb – Creating or updating rootkit system file system files.
locate filename – find file with locate. It has been assumed that you already used the updatedb command.
which filename – Show the top branch of the file (the folder where our file is located).

Network

ifconfig – View the IP list of all connected devices (wireless, network card, VPN, etc.).
Ping Host – Getting Ping from Hosted Morne Comment.
whois domain – Getting domain information (domain owner, IP, DNS server, …).
dig domain – Get DNS Domain Information.
dig -x host – View the host in reverse.
wget file – Download a file from the internet.
wget -c file – Continue to download a stopped download.

SSH

The SSH protocol is used for communication and control with the remote system, which defaults to the SSH port number 22. More is used to control the server by a remote user.

ssh user @ host – Connect to the desired host with the username (after which its username will be asked for your password).
ssh -p port user @ host – Connect to the host with the user name specified by the port number
ssh-copy-id user @ host – Add a key to connect the user to this remote system. (For cases where we do not want to enter a password in each connection, sending the original password will compromise the security of the host, but the key is valid only for the current system and the username being used).

 

Manage users

adduser accountname – Build a new user in your Linux system.
passwd accountname – Change the password of the desired user.
su – Logon to the command line with root user (root user has access to all files and system settings).
exit – Exit the command line with the current user.

Start and end

shutdown -h now – shutdown the system.
halt – Stop all processes (such as turning off the system).
shutdown -r 5 – Restart (reset) the system within 5 minutes.
shutdown -r now – reset the Linux system.
reboot – Rebooting the Linux system (like the above command).

Install programs

Normally, if the source of the program is at our disposal, we will go to the source directory and apply the following commands for installation.
./configure
make
make install
If you are using specific Linux distributions, use the following commands (or special distribution commands) to install the software package provided for that distribution.
dpkg -i pkg.deb – Debian package installation – for distributions Debian, Ubuntu, Mint and more.
rpm -Uvh pkg.rpm – Installing the RPM bundle – for Red Hat, Fedora and … distributions.

print

1- /etc/rc.d/init.d/lpd start – Getting started printing system.
2- /etc/rc.d/init.d/lpd stop – End printing system.
3- /etc/rc.d/init.d/lpd status – View the printing system status.
lpq – View the jobs in the print queue.
lprm – Remove jobs in print queue.
lpr – Print a file.
lpc – Print control settings.
me subject | lpr – Print a manual for a text order.
me-t subject | lpr – Print a manual for a script command.
printtool – Start the desired printer installation interface.

Management of Processes

ps – View active processes.
top – View all running processes.
kill pid – eliminate the desired processing with the pid id.
killall proc – eliminate all processes called proc. Take caution in implementing it.
bg – Show stopped or paused processes (puse) in the background and continue pairing.
fg – Bringing things done recently in the foreground.
<strong>> fg_n_ – bring n work in the foreground task.

How to handle commands

apropos subject – List of pages of the manual for the topic.
man -k keyword – Show pages containing the desired keyword.
man command – View the manual for the desired command.
me-t me | ps2pdf -> man.pdf – Create a pdf file from the manual page.
which command – Show the complete path of the desired command.
time command – Displays the length of the desired command.
whereis app – View the potential route of the desired application.
which app – Displays the application that runs by default.