Basic Linux Commands Every New Programmer Should Know

by Montel Anthony
Basic Linux Commands Every New Programmer Should Know

If you are a new programmer and just starting out in the Linux world, there are some tools that you must know that would help you in your command line. Learner who can understand these essential Linux commands will be armed with the basic knowledge that they require in order to manage directories, files, permissions, and even systems.

Read the article on How To Use Linux Tail Command With Head Command

Key Takeaways:

  • Commands such as: “change directory,” “launch directory,” “print working directory,” and “search”
  • Creating and removing files and directories using mkdir, rm, mv, cp, touch Printing files using cat; Viewing files using less, head and tail; Modifying file permission using chmod; Changing file ownership using chown
  • Processes and tasks control with ps, top, kill, bg, fg, jobs
  • General network and systems utilities such as ping, df, du, free, uptime
  • Trying to use root account through sudo, su
  • Compression/archiving of file using tar, gzip
  • Here are a few examples of the text processing and streams using some of the terminal commands like grep, sort, wc, sed, awk, cut, xargs.
  • The ‘apt’, ‘yum’, and ‘dnf’ package managers

Below are 50 basic Linux commands that new programmers can learn; let’s discuss them as follows.

Essential Navigation Commands

It is always frustrating when working on the Linux operating system especially when you are a freshman; therefore, it is always important to get familiar with how to maneuver around the directories. Here are some of the core navigation and location commands you’ll be using constantly:Here are some of the core navigation and location commands you’ll be using constantly:

1. cd

Stands for “change directory”. Next is the path to the specific directory that you would wish to move into or work within. For example:

cd /home/myfolder

Navigates to the “myfolder” directory that is found in the home directory of the Linux operating system namely /home/.

2. ls

First, the program provides the contents of the current working directory. Also can use other path instead of the current one for example. Common options:

  • ls -l – This option gives you the list of files and directories in the current folder
  • ls -a – This command list all the files and folders in the folder inclusive of the hidden ones.

3. pwd

“print working directory”. Shows the current directory which you are in, it also shows the whole directory path. Incredibly useful whenever you find yourself in the middle of nowhere and do not know where to go.

4. find

Sturdy command that allows searching files according to some of the criteria with quite a lot of variations. Here is basic syntax:

find [path] [criteria] 

An example searching the root directory for PDF files:An example searching the root directory for PDF files:

find / -name "*. pdf"

These are the fundamental commands that ought to be your go-to tools when it comes to movement and search for files/folders in Linux environment.

File and Directory Manipulation

What use is it to navigate if one cannot move into files and directories as well as within the operating system? Here are some foundational commands for handling files:Here are some foundational commands for handling files:

5. mkdir

“make directory”. This command helps one to create a new directory provided the name of same to be created. For example:

mkdir newfolder

Has a working directory and makes “newfolder” in it.

6. rm

Stands for ‘remove’, which is used to delete both files and directories. Common options:

  • rm -r – This command deletes directories and their contents, and applies the changes immediately.
  • `rm -f’ – this command will erase the file(s) without asking for permission (useful when you know what you are doing).

Use with caution! Lost files mean that the files are gone and cannot be restored.

7. mv

[“move”] – Copies a file or a directory and, at the same time, deletes the source file or directory. Basic syntax:

mv source destination

And so you could navigate the files to the different folders or even rename the particular file. Appending flags like -f causes an overwrite of the destination file.

8. cp

“copy” – Copy files. Copies a given source file and placed the copy at the desired destination. For example:

cp original. txt duplicate. txt

Now, we have copied original. txt file into a new file named as duplicate. txt.

9. touch

Easily create empty files. To create file in the Terminal, just type ‘touch filename’ and you will have an empty file immediately.

Yes, there are quite a number of other useful file manipulation tools, but the ones described above should be sufficient to get you on the right path.

Now let’s examine the process in managing files permission and owners as follows:

10. chmod

While using the Linux operating system, each individual file and directory constitute an access control list that determines who can perform a read, write or execute operation on the file. The chmod command enables one to check on the permissions and also change them.

The permissions are split into three groups:The permissions are split into three groups:

  • Owner – This field records the identity of the owner of a file or a folder.
  • Group – The user group linked to the entity
  • Other – They include all other users of the system.

The basic syntax is:

chmod [permissions] [file/folder] 

Permissions can be coded in binary format wherein read permission has 4, write permission has 2 and the execute permission has 1.

So for example, to give owner read/write access and allow the group and others only to read a file:So for example, to give owner read/write access and allow the group and others only to read a file:

chmod 644 file. txt

11. chown

Commands like `chown’ (from change owner) can be used to pass on the ownership of a certain file/folder to a particular system user. This requires super user privileges to be run on the system.

By learning these important skills about dealing with files on Linux, you will be well-equipped for your Linux journey ahead!

Finally, let’s consider how running processes are managed…

Process Management

In programming, you often need to know what programs and processes are currently working, kill process that may have gone amok, and to put in the background processes that aren’t necessary at the moment. Here are some key commands:Here are some key commands:

12. ps

Displays the programs currently enabled under the current ClientID. If you are interested in seeing all the processes running on the system, then you can type the following command. Try:

ps aux

13. top

Allows you to view currently running processes and the condition of the system resources. Press ‘q’ to quit the top display or pressing ‘Enter’ to go back to the list.

14. kill

The kill command is used to terminate a certain process based on its identification number. This way, you need to make sure you properly identify the unruly process first with ps!

kill 12345

15. bg

Initiates a process to be executed out of sight and at an unknown time. Makes sense for putting a stop to an accidental foreground-only command like ‘top’ that could lock your terminal session.

16. fg

Reschedules the most recently backgrounded process to the foreground. Perfect companion to bg!

17. jobs

Outputs all the processes that are currently running in the background under your user ID. Gives you their PID and whether it is currently ‘running’ or ‘stopped’.

These process management tools will help allow you to regain control of even the most out of control Linux processes!

Well let me see what I can find out that could be of interest in the way of system administration 101…

Administrative Privileges

A lot of commands used to analyze and configure system resources work only if executed with root privileges. Here are two commands for running scripts and programs as the root user or temporarily gaining a root shell:Here are two commands for running scripts and programs as the root user or temporarily gaining a root shell:

18. sudo

Stands for “superuser do”. Put this before another command to execute it with the privileges of the administrator. For example:

sudo apt update

Will upgrade local system software packages in the root account. Sometimes you will be asked to enter the user password when using sudo.

19. su

When you want to temporarily become the root or another system user use the command su. Using su without a username allows the system to perform the command on root. You can switch back to your original ID with exit once you are done.

Employ the two commands cautiously in order to perform administrative tasks on your Linux systems as desired!

However, let us as see some commands for acquisition of system information…

Network and System Information

These handy commands give you visibility into disk usage, memory utilization, your network configuration, and more:These handy commands give you visibility into disk usage, memory utilization, your network configuration, and more:

20. ping

The original `ping’ has sent the test packets to the indicated IP address or the domain name and gives the information about the network connectivity and the latency. I have found this article very helpful as a networking troubleshooting tool!

21. df

Information about usage and availability of the disk space of the mounted filesystems in the computer. Put the -h flag in order to get more human friendly output.

22. du

It is used for computing approximate space and size of files in a directory. I consider it particularly useful before copies or backups are done.

23. free

Displays the total memory, amount of memory used, memory that is free, memory that is available for other processes, memory that is being held for later use, memory being used by the kernel. Good for identifying cases where a program is gradually consuming more memory or where resources are generally insufficient.

24. uptime

Instantly determine the amount of time that has elapsed since the system started and the last time it was rebooted. This is an indication of CPU/IO saturation and the load average is also reported here.

These information commands should belong to the list of the basic Linux commands every new user should know when it comes to fixing problems or keeping an eye on the system.

Moving on, let’s discuss archiving files and compressing data?

File Compression/Archiving

Since disk space is expensive and the transfer of data is equally dangerous, understanding the techniques of compression and archiving is crucial. The main tools in a Linux user’s toolbox are:The main tools in a Linux user’s toolbox are:

25. tar

tar – tape archive is a flexible program that can create an archive file with the extension `. tar’ with multiple files and folders. Common flags:

  • -c – when used it creates a new tar file
  • -x – This option extracts files from the existing tar where specified files and folders are stored.

Often used alongside other compression options such as gzip using the -z parameter or bzip using the -j parameter.

26. gzip

An incredibly effective format for data compression that Linux users frequently employ. Employ the Lempel-Ziv (LZ77) technique. Utilized through the use of ‘gzip’ and ‘gunzip’ which are commands that compress and uncompress files that end with .gz.

These two utilities are your primitive instruments for packing the program files, data files, and the trees of files. Crucial for releasing code or reducing the disk usage as well.

So now let’s look at some text processing heavyweight players…

Text Processing

What good is a mass of data if it cannot be chopped to pieces, rearranged and analyzed? Linux offers incredibly powerful text processing capabilities – here is a sampling:Linux offers incredibly powerful text processing capabilities – here is a sampling:

27. grep

It is one of the most widely used methods for searching for specific, required lines in a text file and printing them. It is virtually similar to “Global Regular Expression Print”. The basic syntax is:

grep [options] pattern [files]

For example, recursively search Python files for the import keyword:For example, recursively search Python files for the import keyword:

grep -r import *. py

28. sed

Stands for “stream editor”. Enables more complex text transformation and substitution qualities with the help of regex and markers. Here, there are too many to list, but it’s incredible how much can be accomplished with sed; I could write an entire book on tips and tricks with the program!

29. awk

A great text processing system would be to define data patterns and the related actions to them. Divides input into records and fields to be manipulated, into which the input to be processed is divided. Here is a simple example printing the 5th field of a space-delimited file:Here is a simple example printing the 5th field of a space-delimited file:

awk '{print $5}' file. txt

30. sort

To organize text documents, sort lines of the text files alphanumerically. For example:

sort file. txt

Will sort the elements in the array in a way that they’ll appear in order.

These are just a few of the numerous and versatile text manipulating utilities that are present in the Linux operating systems. They form an entire entity and culture of their own with the Linux world on its own.

That said, let’s try to comprehend what Linux software package management is all about.

Software Package Management

Almost all significant adaptations of Linux have their own inherent package manager, which is used for compilation, uninstallation, and upgrade of applications. Here are some of the most common:Here are some of the most common:

31. apt

APT has become the standard front-end for the Advanced Packaging Tool or the apt on Debian, Ubuntu, Linux Mint, and others. Common operations are:

apt-get update # Updates the package databases.
apt upgrade # the command that upgrades installed packages
sudo : apt install <package> # New application
apt remove <package> # To uninstall apps

32. yum

YUM is the Yellowdog Updater Modified and is available in Red Hat, CentOS, Amazon Linux and Fedora. Similar commands to apt:

yum update # Update package DB to check for updates in the food related packages 
yum install <package> #Install an application
yum remove <package> #Removes the package

33. dnf

Latter versions of fedora have introduced another tool – Dandified Yum, or dnf, as successor to yum – it works similarly but under the hood it is slightly different.

I think regardless of the distro you are running, it is mandatory that you learn the native package management tool! This will take care of the most basic and important considerations.

Conclusion

I think that sums up a brief and comprehensive look at the 50 best Linux commands that are ideal for new programmers. These will enable you to work comfortably with directories, files, processes, system details; and also manage program essentials and automation of certain tasks. These form the basic mundane bureaucratic tools every Linux user should be in possession of.

The topics we have covered:The topics we have covered:

  • Directory management – change directory, list contents, display path, search
  • Files/Directories – mkdir [ Create directory], rmdir [Remove directory], rm [Remove files/Directories ], mv [Move/copy files and directories], cp [Copy files and directories], touch [Creates an empty file], chmod [Change file permission], chown [Change file owner].
    Utilities – ps, top, kill, &, fg, jobs
    administrative control – sudo, su
  • System Information command – ping, df, du, free, uptime
    There is also file compression using tools like tar and gzip.
  • Text manipulation – text manipulation utilities like grep, sed, awk, sort.
  • Package Management – Package installer or Package downloader, yum and dnf

So, I encourage you to go out and start using these Linux commands based on the knowledge acquired in this article. These will stand you in good stead no matter what your programmer’s journey looks like! Don’t forget to share in the comments below if you have benefited from any of them.

Related Posts

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blogarama - Blog Directory

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.