DEV Community

Cover image for The Top 10 Linux Commands Every Programmer Should Know
Harvey
Harvey

Posted on

The Top 10 Linux Commands Every Programmer Should Know

Linux systems are powerful operating systems with endless possibilities. However, learning to use this amazing OS can be difficult if you’re new to the Linux world.

You could spend days browsing through forums, copy/pasting code and never really knowing what’s going on or why it works. If you want to learn commands, I recommend this site.

Enter the Command Line

My first tip is pretty basic, but very important. Before you can run any of these commands, you’ll need to start the terminal.

One way is to enter the terminal outside of the GUI. X11 or Wayland provides the graphical user interface on linux. You can switch to the terminal by pressing Alt+Ctrl+F1 to F12.

You can also start a graphical terminal. There are many variants like gnome-terminal, konsole, xterm, kitty and many others.

terminal in gnome

The Linux Command Line is a powerful tool every programmer should know, even if they don't use linux. It is also a dangerous weapon that can lead to potential disaster if it is used improperly. So, which are the essential commands that a programmer needs to know?

The mkdir command

The mkdir command allows you to create directories. You can also give it an optional -p flag to create any needed parent directories along with the directory itself.

mkdir folder
Enter fullscreen mode Exit fullscreen mode

The ll command

The ll command lets you see the files and folders in a directory. It has several useful options such as showing the file size, permission mode, and more.

$ ll
total 2097256
drwxr-xr-x  20 root root       4096 jun  4  2021 ./
drwxr-xr-x  20 root root       4096 jun  4  2021 ../
lrwxrwxrwx   1 root root          7 jun  4  2021 bin -> usr/bin/
drwxr-xr-x   4 root root       4096 mei 28 18:31 boot/
drwxrwxr-x   2 root root       4096 jun  4  2021 cdrom/
drwxr-xr-x  21 root root       4780 mei 28 20:43 dev/
drwxr-xr-x 153 root root      12288 mei 28 18:31 etc/
drwxr-xr-x   3 root root       4096 apr  6 14:20 home/
lrwxrwxrwx   1 root root          7 jun  4  2021 lib -> usr/lib/
lrwxrwxrwx   1 root root          9 jun  4  2021 lib32 -> usr/lib32/
lrwxrwxrwx   1 root root          9 jun  4  2021 lib64 -> usr/lib64/
lrwxrwxrwx   1 root root         10 jun  4  2021 libx32 -> usr/libx32/
drwx------   2 root root      16384 jun  4  2021 lost+found/
drwxr-xr-x   3 root root       4096 apr 24 15:24 media/
drwxr-xr-x   2 root root       4096 feb  9 19:47 mnt/
drwxr-xr-x   2 root root       4096 feb  9 19:47 opt/
dr-xr-xr-x 269 root root          0 mei 28 19:10 proc/
drwx------  10 root root       4096 mei 23 20:00 root/
drwxr-xr-x  35 root root        920 mei 28 20:02 run/
lrwxrwxrwx   1 root root          8 jun  4  2021 sbin -> usr/sbin/
drwxr-xr-x  17 root root       4096 mei 25 01:18 snap/
drwxr-xr-x   2 root root       4096 feb  9 19:47 srv/
-rw-------   1 root root 2147483648 jun  4  2021 swapfile
dr-xr-xr-x  13 root root          0 mei 28 19:10 sys/
drwxrwxrwt  20 root root      20480 mei 28 21:19 tmp/
drwxr-xr-x  14 root root       4096 feb  9 19:48 usr/
drwxr-xr-x  14 root root       4096 feb  9 19:56 var/
Enter fullscreen mode Exit fullscreen mode

cat

The cd command 😁

The cd (change directory) command lets you move around within your Linux filesystem.

You'll find yourself using it constantly. Here's an example of how it works:

cd Documents
cd Linux\ Box\ Archive
cd
Enter fullscreen mode Exit fullscreen mode

To list files, type ls.

The rm command

The rm command removes files and folders. It removes it completely from your system, it doesn't put it in a trash can.

rm -rf folder
Enter fullscreen mode Exit fullscreen mode

cp

Copies files and directories within the same directory or between two directories

cp [option] [source] [target]
Enter fullscreen mode Exit fullscreen mode

Example:

cp mydoc.doc mydoc_new.doc
Enter fullscreen mode Exit fullscreen mode

Linux tree command πŸ’»

The tree command provides us with a way to get an overview of files and folders and how they are structured in our directories. The tree command is used like that: tree

$ tree -d -L 1
.
β”œβ”€β”€ bin -> usr/bin
β”œβ”€β”€ boot
β”œβ”€β”€ cdrom
β”œβ”€β”€ dev
β”œβ”€β”€ etc
β”œβ”€β”€ home
β”œβ”€β”€ lib -> usr/lib
β”œβ”€β”€ lib32 -> usr/lib32
β”œβ”€β”€ lib64 -> usr/lib64
β”œβ”€β”€ libx32 -> usr/libx32
β”œβ”€β”€ lost+found
β”œβ”€β”€ media
β”œβ”€β”€ mnt
β”œβ”€β”€ opt
β”œβ”€β”€ proc
β”œβ”€β”€ root
β”œβ”€β”€ run
β”œβ”€β”€ sbin -> usr/sbin
β”œβ”€β”€ snap
β”œβ”€β”€ srv
β”œβ”€β”€ sys
β”œβ”€β”€ tmp
β”œβ”€β”€ usr
└── var
Enter fullscreen mode Exit fullscreen mode

If you change it to L2, it goes a level deeper. There is no limit to how many levels you can go.

$ tree -d -L 2
...
β”œβ”€β”€ usr
β”‚Β Β  β”œβ”€β”€ bin
β”‚Β Β  β”œβ”€β”€ games
β”‚Β Β  β”œβ”€β”€ include
β”‚Β Β  β”œβ”€β”€ lib
β”‚Β Β  β”œβ”€β”€ lib32
β”‚Β Β  β”œβ”€β”€ lib64
β”‚Β Β  β”œβ”€β”€ libexec
β”‚Β Β  β”œβ”€β”€ libx32
β”‚Β Β  β”œβ”€β”€ local
β”‚Β Β  β”œβ”€β”€ sbin
β”‚Β Β  β”œβ”€β”€ share
β”‚Β Β  └── src
└── var
    β”œβ”€β”€ backups
    β”œβ”€β”€ cache
    β”œβ”€β”€ crash
    β”œβ”€β”€ lib
    β”œβ”€β”€ local
    β”œβ”€β”€ lock -> /run/lock
    β”œβ”€β”€ log
    β”œβ”€β”€ mail
    β”œβ”€β”€ metrics
    β”œβ”€β”€ opt
    β”œβ”€β”€ run -> /run
    β”œβ”€β”€ snap
    β”œβ”€β”€ spool
    └── tmp
Enter fullscreen mode Exit fullscreen mode

vim editor

vim is an editor which is popular among programmers, especially among Linux enthusiasts.

vim filename
Enter fullscreen mode Exit fullscreen mode

Vim or it's older variant vi is everywhere, on Mac OS X, on servers etc. It has quite a steep learning curve, you can practice by exercise

To exit vim press ZQ.

vim text editor

grep in files

Using the command grep, we can search for a specific character pattern inside a file or files.

You can use it like:

grep word filename
Enter fullscreen mode Exit fullscreen mode

sha256sum

This commands allow you to compare file contents to see if their contents are equal, or to test if the file has been changed in any way.

It creates a unique hash for the file contents. This way you can check if the file has been changed if you send it over the internet.

sha256sum file.txt
Enter fullscreen mode Exit fullscreen mode

This returns a unique hash for the file.

the ifconfig command

This command is used for network configuration. If you want to assign a static IP address, you need to use this command

Top comments (0)