Linux commands for beginners

As a beginner in the world of Linux, one of the first things you should learn is how to use the command line interface. While this may seem intimidating at first, mastering the command line can greatly increase your productivity and efficiency when working with Linux

To get started, I recommend using Ubuntu as your first Linux distribution. It is easy to use, comes with a user-friendly interface, and has a large community that can help you get started.

In this article, we will discuss some of the most useful Linux commands that every beginner should know.

It’s essential to understand that using commands can be risky, especially if you’re not familiar with them. Commands can cause unintended consequences, such as deleting important files or damaging your system. Therefore, it’s important to exercise caution when using commands and follow the instructions carefully.

To minimize the risk of making mistakes, we recommend that you back up your data before attempting to use any commands. Additionally, if you’re not familiar with a particular command, we suggest you do some research or consult with an expert to avoid any potential issues.

ls

The ls command is used to list the files and directories in the current working directory

# To list files and directories in the current working directory
ls

# To list all files and directories (including hidden ones) 
# in the current directory
ls -a

# To list all files in a directory with details 
#(e.g. size, permissions)
ls -l

# To list all files in a directory with details
# showinth the newst first
ls -lt

# To list files and directories in a specific directory
ls /path/to/directory

As you can see in line 14 you can combine several options in the same comand.

cd

The cd command is used to change the current working directory.
# To change to the home directory
cd ~

# To change to a specific directory
cd /path/to/directory

# To change to the parent directory
cd ..

# To change to a directory using a full path
cd /full/path/to/directory

mkdir

The mkdir command is used to create a new directory.

# To create a new directory in the current directory
mkdir new_directory

# To create a new directory in the upper directory
mkdir ../new_directory

# To create multiple directories at once
mkdir -p /path/to/new/directory

# To create a directory using a full path
mkdir /full/path/to/new_directory

rm

The rm command is used to remove files and directories.
# To remove a file
rm filename

# To remove a directory (and its contents)
rm -r directory_name

# To remove a directory without confirmation
rm -rf directory_name

# To remove a file using a full path
rm /full/path/to/file

Pay special attention when you use this command, as you can lose information permanently

pwd

The pwd command is used to print the current working directory.

# To print the current working directory
pwd

# To print the full path of the current working directory
pwd -P

cp

The cp command is used to copy files and directories

# To copy a file
cp source_file destination_file

# To copy a directory (and its contents)
cp -r source_directory destination_directory

# To copy a file using a full path
cp /full/path/to/source_file /full/path/to/destination_file

# To copy a directory using a full path
cp -r /full/path/to/source_directory /full/path/to/destination_directory

mv

The mv command is used to move or rename files and directorie
# To move a file
mv source_file destination_file

# To rename a file
mv old_filename new_filename

# To move a directory
mv source_directory destination_directory

# To move a file using a full path
mv /full/path/to/source_file /full/path/to/destination_file

# To move a directory using a full path
mv /full/path/to/source_directory /full/path/to/destination_directory

sudo

The sudo command is used to execute a command with administrative privileges
# To execute a command with administrative privileges
sudo command

# To become the root user
sudo su

# To execute a command with administrative privileges using a full path
sudo /full/path/to/command

grep

The grep command is used to search for a pattern

# To search for a pattern in a file
grep pattern filename

# To search for a pattern in multiple files
grep pattern file1 file2

# To search for a pattern in all files in a directory
grep pattern /path/to/directory/*

# To search for a pattern recursively in all files in a directory
grep -r pattern /path/to/directory

find

The find command is used to search for files

# To find files with a specific name in a directory
find /path/to/directory -name filename

# To find files modified within the last 24 hours
find /path/to/directory -mtime 0

# To find files larger than a specific size
find /path/to/directory -size +10M

# To find files with a specific extension in a directory
find /path/to

Some extras

Magic TAB

One helpful tip for navigating the command line interface in Linux is to use the Tab key for auto-completion.

If you start typing a command or file name and then press the Tab key, Linux will automatically try to complete the command or file name for you.

This can save time and reduce the chance of typos or errors. Additionally, if there are multiple files or directories that match what you’ve typed, you can press Tab twice to see a list of possible matches.

Help!

Use the built-in help system. Many commands in Linux have a manual page that provides detailed information on how to use the command, including a description of its options and arguments.

To access the manual page for a command, you can use the “man” command followed by the name of the command. Another way to access the command help is using — help option after the command

What’s the case?

As a final note, it’s important to remember that Linux is case sensitive, which means that “file.txt” and “File.txt” are two different files. So be careful when entering commands or working with files in Linux.

In conclusion

These are some of the most useful Linux commands that every beginner should know. While there are many more commands that you can learn, mastering these basic commands will allow you to perform most of the tasks that you need to do on