Linux basics for programmers

Linux basics for programmers

·

8 min read

Linux is a family of open-source Unix based operating systems, that are based on the Linux Kernel. This includes popular Linux based systems like Kali-Linux, ParrotOs, Ubuntu, Fedora, Mint, Debian, and others. More accurately, they are called Linux distros.

Here is a list of basic Linux commands:

  1. cd command
cd fileName

To navigate through the Linux files and directories, use the cd command. It requires either the full path or the name of the directory, depending on the current working directory that you’re in. Let’s say you’re in /home/username/Documents and you want to go to Photos, a subdirectory of Documents. To do so, simply type the following command: cd Photos. Another scenario is if you want to switch to a completely new directory, for example,/home/username/Movies. In this case, you have to type cd followed by the directory’s absolute path: cd /home/username/Movies.

There are some shortcuts to help you navigate quickly:

  • cd .. (with two dots) to move one directory up

  • cd to go straight to the home folder

  • cd- (with a hyphen) to move to your previous directory

2. pwd command

pwd

Use the pwd command to find out the path of the current working directory where you’re in. This command will return an absolute path, which is basically a path of all the directories that starts with a forward slash (/). An example of an absolute path is /home/username.

  1. ls command
ls

If you want to see the content of other directories, type ls and then the directory’s path. For eg., enter ls /home/username/Documents to view the content of Documents.

There are variations you can use with the ls command:

  • ls -R will list all the files in the sub-directories as well

  • ls -a will show the hidden files

  • ls -al will list the files and directories with detailed information like the permissions, size, owner, etc.

4. cat command

cat

cat (short for concatenate) is one of the most frequently used commands in Linux. It is used to list the contents of a file on the standard output (sdout). To run this command, type cat followed by the file’s name and its extension. For instance: cat file.txt.

cat > filename creates a new file

cat filename1 filename2>filename3 joins two files (1 and 2) and stores the output of them in a new file (3)

to convert a file to upper or lower case use, cat filename | tr a-z A-Z >output.txt

5. cp command

cp

Use the cp command to copy files from the current directory to a different directory. For instance, the command cp scenery.jpg /home/username/Pictures would create a copy of scenery.jpg (from your current directory) into the Pictures directory.

6. mv command

mv

The primary use of the mv command is to move files, although it can also be used to rename files.

The arguments in mv are similar to the cp command. You need to type mv, the file’s name, and the destination’s directory. For example: mv file.txt /home/username/Documents.

To rename files, the Linux command is

 mv oldname.ext newname.ext

7. mkdir command

mkdir

we use mkdir command to make a new directory — if you type mkdir subbu it will create a directory called subbu.

8. rmdir command

rmdir

when you need to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty directories.

we can use rm command as alternative of rmdir

rm -r

9. sudo command

sudo

“SuperUser Do”, this command enables you to perform tasks that require administrative or root permissions. However, it is not advisable to use this command for daily use because it might be easy for an error to occur if you did something wrong.

10. ping command

ping www.saurabhsanap.tech

Use the ping command to check your connectivity status to a server. For example, by simply entering ping any_working_web_url, the command will check whether you’re able to connect to Google and also measure the response time.

11. wget command

wget download_link

we can download files from the internet with the help of the wget command.

12. history command

history

When we’ve been using Linux for a certain period of time, we’ll quickly notice that you can run hundreds of commands every day. As such, running history command is particularly useful if you want to review the commands you’ve entered before in history.

13. man command

man sudo

Confused about the function of certain Linux commands? Don’t worry, you can easily learn how to use them right from Linux’s shell by using the man command. For instance, entering man tail will show the manual instruction of the tail command.

14. zip, unzip command

zip
unzip

Use the zip command to compress your files into a zip archive, and use the unzip command to extract the zipped files from a zip archive.

15. useradd, userdel command

useradd
userdel

Since Linux is a multi-user system, this means more than one person can interact with the same system at the same time. useradd is used to create a new user, while passwd is adding a password to that user’s account. To add a new person named subb type, useradd subb and then to add his password type, passwd 123456789

To remove a user is very similar to adding a new user. To delete the users account type, userdel UserName