M. Niyazi Alpay
M. Niyazi Alpay
M. Niyazi Alpay

I've been interested in computer systems since a very young age, and I've been programming since 2005. I have knowledge in PHP, MySQL, Python, MongoDB, and Linux.

 

about.me/Cryptograph

Linux Command Line - Common Linux Commands

Linux Command Line - Common Linux Commands

Today, Linux operating systems come with a beautiful interface designed for end-users, but the majority of tasks can still be done via the command line. The reason many computer users shy away from Linux is the command line, although everything can now be managed through a graphical interface, the command line still reigns supreme.

You can access and configure everything from simple system settings to complex network configurations from the command line.

The dmesg command allows us to review messages shown during system boot-up, helpful for identifying unrecognized hardware, etc. Later, you can inspect your devices in detail using commands like lspci and lsusb.

Linux views every action as a process. With the top command, you can view system resources and identify the processes consuming the most resources. Additionally, the ps command provides detailed information about processes.

For security reasons, Linux has file permissions, users, and groups. You can adjust file ownership and permissions using commands like chmod and chown.
chmod +x makes a file executable, while chmod 777 grants all permissions to a file.

chmod 777 filename

With chown, you can change the user and group of a file.
chown username filename

The man command is the most useful command for beginners in Linux. With the man command, you can learn about other commands.
man cat

The cat command provides an output explaining the purpose of the command named 'cat'.

You can use the cat command to read information within a text document.
cat filename.txt

To search from the command line, you can use find and locate commands.
If you want to find the location of a file on your computer, searching with locate filename will bring its path, or if we are in a folder and want to see if the file we are looking for is in that folder, we can search with find filename.

In Linux, the most privileged user is the root user. Some operations require us to be a privileged user; to achieve this, we prefix the command with sudo.

sudo apt-get install linux-headers-$(uname -r)

installs the linux-headers that are compatible with the current kernel.

To use the command line with full root privileges, you can use the command
sudo su
The system will ask us to enter our password when we want root privileges.

To change directories in the command line, use the cd command.
cd /home/username

To go up one directory, use
cd ..

pwd displays the path of the current directory,
whoami displays your username when logging into the system.
Imagine you've sat down at a computer with Linux installed, and the owner forgot to lock the computer. By using the whoami command in the command line, you can find out the current user.

Many commands don't provide much information on their own. For example, the uname command. We can learn about system-related information such as the operating system, processor, and kernel.
uname outputs "Linux" when used alone.
uname -a provides the kernel version and processor information together.
uname -r provides the kernel version.

ls = List files command.
ls -l = Provides detailed information including file size, chmod information, etc.

The --help parameter is a commonly used help parameter for all commands. It tells us about the parameters that can be used with the command and their functions.

I mentioned the ps command above, it provides information about processes, but it does this with parameters.
ps --help provides detailed information.
ps -ax | grep firefox
lists the processes of Firefox.

The kill command is used to terminate an application.
kill process_id

We can reach the pid number with ps -ax | grep process_name.

The free command shows us memory usage, how much RAM is being used, and how much is free.


Linux's most popular command - grep

Global Regular Expression Printer - means it extracts parts from a given text according to certain criteria.
You're reading a text document
cat filename | grep string_to_extract

and you'll see only the part we want from that file.

There are two ways to use it: standalone or with pipes (|).

Stand-alone

grep 'niyazi' /home/niyazi/log.txt

lists all lines containing 'niyazi' in log.txt under /home/niyazi.

grep -l 'niyazi' /project/*.php

lists the names of files containing 'niyazi' in /project directory with a .php extension. Only file names are listed, not lines.

Filtering

ls -l | grep rwxrwxrwx

lists files with read, write, and execute permissions.

netstat -an | grep :80

lists IPs connected to your computer via port 80.

For detailed information about commands, you can check here.

You may also want to read these

There are none comment

Leave a comment

Your email address will not be published. Required fields are marked *