The Top 10 Linux Commands Every Programmer Should Know

harvey

Harvey

Posted on May 28, 2021

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

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
harvey
Harvey

Posted on May 28, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About