Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 9, 2023 06:00 pm GMT

Bookmark This: The 10 Most-Used Linux Commands You Should Know

Linux is free and open-source, has better security than its competitors, and boasts a powerful command line that makes developers and power users more effective.

Whether youre an experienced Sysadmin or a Linux newcomer, you can take advantage of this guide. Many of these have multiple options you can string to them, so make sure to check out the commands manual.

But first, make sure to fire up a terminal. In most Linux distributions, you would use Ctrl + Alt + T to do so. If this isnt working, search in your application panel for terminal.

Lets begin!

1. ls Command

ls is probably the first command every Linux user typed in their terminal. It allows you to list the contents of the directory you want (the current directory by default), including files and other nested directories.

ls

It has many options, so it might be good to get some help by using the --help flag. This flag returns all the flags you can use with ls.

For example, to colorize the output of the ls command, you can use the following:

ls --color=auto

The colorized ls command.

Now the ls command output is colorized, and you can appreciate the difference between a directory and a file.

But typing ls with the color flag would be inefficient; thats why we use the alias command.

2. alias Command

The alias command lets you define temporary aliases in your shell session. When creating an alias, you instruct your shell to replace a word with a series of commands.

For example, to set ls to have color without typing the --color flag every time, you would use:

alias ls="ls --color=auto"

As you can see, the alias command takes one key-value pair parameter: alias NAME="VALUE". Note that the value must be inside quotes.

If you want to list all the aliases you have in your shell session, you can run the alias command without argument.

alias

The alias command.

3. unalias Command

As the name suggests, the unalias command aims to remove an alias from the already defined aliases. To remove the previous ls alias, you can use:

unalias ls

4. pwd Command

The pwd command stands for print working directory, and it outputs the absolute path of the directory youre in. For example, if your username is john and youre in your Documents directory, its absolute path would be: /home/john/Documents.

To use it, simply type pwd in the terminal:

pwd# My result: /home/kinsta/Documents/linux-command

5. cd Command

The cd command is highly popular, along with ls. It refers to change directory and, as its name suggests, switches you to the directory youre trying to access.

For instance, if youre inside your Documents directory and youre trying to access one of its subfolders called Videos, you can enter it by typing:

cd Videos

You can also supply the absolute path of the folder:

cd /home/kinsta/Documents/Videos

6. cp Command
Its so easy to copy files and folders directly in the Linux terminal that sometimes it can replace conventional file managers.

To use the cp command, just type it along with the source and destination files:

cp file_to_copy.txt new_file.txt

You can also copy entire directories by using the recursive flag:

cp -r dir_to_copy/ new_copy_dir/

Remember that in Linux, folders end with a forward slash (/).

7. rm Command
Now that you know how to copy files, itll be helpful to know how to remove them.

You can use the rm command to remove files and directories. Be careful while using it, though, because its very difficult (yet not impossible) to recover files deleted this way.

To delete a regular file, youd type:

rm file_to_copy.txt

If you want to delete an empty directory, you can use the recursive (-r) flag:

rm -r dir_to_remove/

On the other hand, to remove a directory with content inside of it, you need to use the force (-f) and recursive flags:

rm -rf dir_with_content_to_remove/

Info: Be careful with this you can erase a whole day of work by misusing these two flags!

8. mv Command
You use the mv command to move (or rename) files and directories through your file system.

To use this command, youd type its name with the source and destination files:

mv source_file destination_folder/mv command_list.txt commands/

To utilize absolute paths, youd use:

mv /home/kinsta/BestMoviesOfAllTime ./

where ./ is the directory youre currently in.

You also can use mv to rename files while keeping them in the same directory:

mv old_file.txt new_named_file.txt
  1. mkdir CommandTo create folders in the shell, you use the mkdir command. Just specify the new folders name, ensure it doesnt exist, and youre ready to go.

For example, to make a directory to keep all of your images, just type:

mkdir images/

To create subdirectories with a simple command, use the parent (-p) flag:

mkdir -p movies/2004/

10. man Command

Another essential Linux command is man. It displays the manual page of any other command (as long as it has one).

To see the manual page of the mkdir command, type:

man mkdir

You could even refer to the man manual page:

man man

The manual page of man.

Summary
It can take some time to learn Linux, but once you master some of its tools, it becomes your best ally, and you wont regret choosing it as your daily driver.

One of the remarkable things about Linux is that even if youre an experienced user, youll never stop learning to be more productive using it.

Check out our full library of web development deep dives right here: https://kinsta.com/web-development


Original Link: https://dev.to/kinsta/bookmark-this-the-10-most-used-linux-commands-you-should-know-5dfp

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To