Useful Linux Commands — Users, Groups, and Remote Connections

Linux is an operating system that many developers will use.

Therefore, it’s a good idea to learn some Linux commands.

In this article, we’ll look at some useful Linux commands we should know.


printf is an improved version of the echo command.

It lets us format and adds escape sequences:

printf "1\n3\n2"

We can also use it with < to get input from it and sort it with sort :

sort <(printf "1\n3\n2")

0 / 1 / 2

0, 1, and 2 are the standard input, output, and error streams, respectively.

For instance, we can redirect to stdout with:

echo "stdout" >&1

And we can redirect to stderr with:

echo "stderr" >&2


The users command shows all the users currently logged in.

To see all users on the system, we can check /etc/passwd .


To add a user to the system, we run useradd .

For instance, we run:

sudo useradd foo

to add the foo user.


userdel lets us delete the user.

For example, we run:

`sudo` userdel `foo`

to delete the foo user from the system.


groups show all the groups of which the current user is a member.

We can see all groups in the /etc/group .

We shouldn’t change /etc/group unless we know what we’re doing.


groupadd lets us add groups into our system.

We can run:

sudo groupadd foo

to add the foo group.


groupdel lets us delete a group.

We can run:

sudo groupdel foo

to delete a group.


cmp gets the byte difference between 2 files.

For instance, we run:

cmp a b

to get the byte difference between files a and b .


cut lets us cut a line into sections on some delimited.

The -d flag lets us specify a delimiter.

-f specifies the field index to print.

For instance, we run:

printf "" > c
cut -d'.' c -f1

to print 117 onto the screen.


sed lets us replace a string with another string in a file.

For instance, we runL

echo "old" | sed s/old/new/

to remove old with new .


ssh lets us connect from one machine to another machine.

We run:

ssh –p <port> bob@

to connect to machine with IP address with user bob .


We can use scp to copy a file securely from one machine to another.

For instance, we can run:

scp –P <port> hello bob@

to copy the hello file from the machine with IP address


The rsync utility lets us copt files with the least amount of data possible being transmitted.

This is done by looking at changes between files.

For instance, we run:

rsync -av ../s/* .

to sync the files from the ../s directory with the current directory with rsync .

rsync also works over ssh .

We run:

rsync -avz -e "ssh -p <port>" bob@* .

to copy the data over to the machine with IP


We can print files, manipulate users and groups, and connect to other machines with some Linux commands.


Useful Linux Commands — Files and Packages

Linux is an operating system that many developers will use.

Therefore, it’s a good idea to learn some Linux commands.

In this article, we’ll look at some useful Linux commands we should know.


The head command outputs the first few lines of a file.

The -n flag specifies how many lines to shows.

The default number of lines to show is 10.


tail outputs the last few lines of a file.

We can also use the -n flag to specify how many lines to show.

Also, we can get the end of the file beginning with the N -th line with:

tail -n +N


cat concatenates list of files and send them to the standard output stream.


less is a quick tool to let us view a file.

It opens up the file content with a read-only window.


nano is a small text editor.

It’s easy to use for beginners since we don’t have to learn lots of shortcuts.


nedit is a small graphical rextr editor.

And it lets us edit text with point and click, drag and drop, and syntax highlighting.


touch lets us modify the timestamp of an existing file and quickly create a new file.


logout lets us exit the shell we’re logged into.


ncdu lets us display file space usage.

It opens a window that shows the disk usage of each file.


top displays all currently running processes and their owners, memory usage, and more.


htop is an interactive version of top .

We can pass -u username to display processes that are owned by user username .


whereis lets is search for files related to a particular command.

For instance, we run:

whereis ls

to find the path to the ls command and the associated manpage.


whatis prints the description of the command from its man page.


The locate command finds a file anywhere in the system by searching a cached list of files.


find iterates through the file system to find the file we’re looking for.

It looks at files that currently exist in the system.

find lets us search by file age, size, ownership, type, timestamp, permissions, depth within the file system, regex, and more.


wget lets us download a file from the Internet


curl can be used like wget , but we need the --output flag.

curl supports many moe protocols and it’s more widely available that wget .

wget can only receive data, but curl can also send data.

wget can download files recursively, but curl can’t.


The apt command is available in Debian based distros.

It can be used to install, upgrade, or delete software on our machine.

We can run apt search to search for packages. apt install lets us install packages.


Linux distros comes with many commands that we can use to manage files and download files.


Useful Linux Commands — File Operations and Multiple Commands

Linux is an operating system that many developers will use.

Therefore, it’s a good idea to learn some Linux commands.

In this article, we’ll look at some useful Linux commands we should know.


The less command lets us show the content of a file.

The general syntax is:

less <filename>

We can navigate with arrow keys.

Spacebar and b navigates page by page.

/ lets us search for content.

? search backward.

F enters follow mode. When the file is changed, the changes are displayed live.

ctrl+c quits follow mode.


cp lets us move files and folders.

For instance, we run:

cp foo bar

to copy foo to bar .

We can also use it to copy folders with the -r switch:

cp -r fruits cars

We move the fruits folder contents to cars .


The mv command lets us move files and folders.

For instance, we run:

mv foo bar

to move foo to bar .

We can move files into a folder with:

mv grape banana fruits

We move the grape and banana files to the fruits folder.


The ls command lets us list files and folders.

We can list the content of a given folder with:

ls /bin

We can add the a switch to show hidden files.

l shows files permissions, file and folder sizes, and modified date time.

We run ls -al to show all that info.


The rmdir command lets us remove a folder.

We run:

rmdir fruits

to remove the fruits folder.

We can use it to remove multiple folders:

rmdir fruits cars

We remove the fruits and cars folders.

The folders we delete must be empty.

To delete non-empty folders, we run:

rm -rf fruits cars

-r means recursive and f means force.


pwd shows the current working directory.


cd lets us change the current working directory.

For instance, we run:

cd fruits

to go to the fruits folder.

cd .. to move to the home folder.

cd ../cars moves to the parent folder of cars .

We can use absolute paths with cd , so we run cd /etc to go to the /etc folder.


mkdir lets us create a folder.

For instance, we run:

mkdir cars

to create a cars folder in the current working directory.

And we run:

mkdir dogs cars

to create the dogs and cars folders.

We can create multiple nested folders with the -p switch:

mkdir -p fruits/apples


!! lets us run the last command.

; / && / &

; lets us run one command after the other like:

ls; pwd

&& runs multiple commands but the ones on the right won’t run if the left one fails.

& lets us run multiple commands in parallel instead of waiting for the current one to finish before running the next one.


We can run commands to show file content and run multiple commands with some operators with Linux.


Useful Linux Commands — Soft Links and Files

Linux is an operating system that many developers will use.

Therefore, it’s a good idea to learn some Linux commands.

In this article, we’ll look at some useful Linux commands we should know.

Soft Links

We can create soft links with the ln -s command.

The general syntax is:

ln -s <original> <link>

Soft links will be broken with the original file removed.

For instance, we run:

ln -s foo.txt newfoo.txt

to create the newfoo.txt soft link.

We can see that the soft link should have th @ suffix and it’s colored differently when we run the ls -al command.


The find command lets us find files and folders on the file system.

For instance, we can find all files with the .txt extension by running:

find . -name '*.txt'

We need quotes around special characters like * to stop the shell from interpreting them.

We can also he it to find directories with the -type d switch:

find . -type d -name src

-type f lets us search for files only.

-type l lets us search only symbolic libks.

We can also search under multiple root trees:

find folder1 folder2 -name foo.txt

We can also search with multiple keywords with -or :

find . -type d -name node_modules -or -name public

We can exclude results with -not :

find . -type d -name '*.md' -not -path 'node_modules/*'

And we can search for files with at least with the given size with -size :

find . -type f -size +100c

c means bytes.

We can search for files with size in a range with:

find . -type f -size +100k -size -1M

We can search for files that are edited more than a given number of days ago with -mtime :

find . -type f -mtime +3

And we can delete files that are found with the -delete option:

find . -type f -mtime -1 -delete


cat lets us add content to a file.

To print content to standard output, we run:

cat file

To print the content of multiple files, we run:

cat file1 file2

We can redirect the output to a file by running:

cat file1 file2 > file3

We can change > to >> top create the file if it doesn’t exist.

And we can print line numbers with -n :

cat -n file


The touch command lets us create an empty file.

For instance, we run:

touch file

to create a file named file .

If it already exists it opens the file in write mode and the timestamp is updated.


The tail command lets us show the content at the end of a file,

The -f switch watches for file changes and updates the output automatically.

For instance, we run:

tail -f /foo.txt

to watch foo.txt and update the output.

We can change the number of lines printed with -n :

tail -n 10 <filename>

We print the last 10 lines with -n 10 .

We can print the whole file content starting from a specific line with + before the line number:

tail -n +10 <filename>


We can create soft links and create and manipulate files with Linux commands.


Useful Linux Commands — Processes and Links

Linux is an operating system that many developers will use.

Therefore, it’s a good idea to learn some Linux commands.

In this article, we’ll look at some useful Linux commands we should know.


The kill command lets us send signals to a process.

The general format is:

kill <PID>

where PID is the process ID.

We can send signals like:

kill -HUP <PID>
kill -INT <PID>
kill -KILL <PID>
kill -TERM <PID>
kill -CONT <PID>
kill -STOP <PID>

HUP means hang up. It’s sent when a terminal window that started a process is closed before terminating it.

INT means interrupt. It sends the signal when we press ctrl+c.

KILL is sent to the OS kernel to stop and terminate the process.

TERM means terminate. The process that receives it will terminate.

CONT means continue. It lets us resume a stopped process.

STOP is sent to the OS kernel instead of the process, which stops but doesn’t terminate the process.

We can also use a number to replace these signals. 1 is HUP , 2 is INT , 9 is KILL , 15 is TERM , 18 is CONT .


The top command lets us list processes running in real time.

We can quit top with ctrl+c.

And we can sort processes by the amount of memory used by running:

top -o mem


echo lets us print arguments passed to it.

For instance, we run:

echo "hello" >> output.txt

to put hello into the output.txt file.

Also, we can interpolate environment variables in the string:

echo "path=$PATH"

We have to escape special characters like $ in the command.

We can echo the files in the current folder with:”

echo *

And we can echo the files that start with a with:

echo a*

We can print the home folder path with:

echo ~

We can also print the results of a command with $() like:

echo $(ls)


The ps command lets us list the processes currently running in the system.

We can list all processes with the ps ax command.

a is used to list other users’ processes.

x shows processes not linked to any terminal.

ps axww continues the command listing on a new line instead of truncating it.

The output has the PID which is the process ID, TT tells us the terminal ID used.

STAT tells us the state of the process.

I means the process is idle. R is a runnable process. S is a process that’s sleeping for less than 20 seconds.

T is a stopped process, U is a process in uninterruptable wait and Z is a dead process.

+ means the process is in the foreground. s means the process is a session leader.


ln lets us create links in the filesystem.

The syntax of the command is:

ln <original> <link>

For instance, we run

ln foo.txt newfoo.txt

to create the newfoo.txt link to the foo.txt file.

Links are indistinguishable from a regular file from the user’s perspective.


We can manage processes and create symbolic links with Linux commands.