The Top 10 Linux Commands Every Programmer Should Know
Harvey
Posted on May 28, 2021
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.
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
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/
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
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
cp
Copies files and directories within the same directory or between two directories
cp [option] [source] [target]
Example:
cp mydoc.doc mydoc_new.doc
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
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
vim editor
vim is an editor which is popular among programmers, especially among Linux enthusiasts.
vim filename
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.
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
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
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
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
November 28, 2024
November 29, 2024