Linux, a free and open-source operating system, is loved by developers and system administrators for its flexibility, control, and scripting capabilities. It might appear complex, but once you understand the command line basics, navigating Linux becomes a breeze. This article will introduce some of the most popular Linux commands with examples to make your journey smoother.
ls is used to list the contents of a directory.
This command lists all the files and directories present in the
cd is used to change the current directory.
This command changes the current working directory to
pwd (print working directory) displays the full pathname of the current working directory.
This command will display the current working directory.
touch is used to create a new empty file.
This command will create a new file named
file.txt in the current directory.
cp is used to copy files and directories.
cp source.txt destination.txt
This command copies the content of
destination.txt does not exist, it will be created.
mv is used to move or rename files.
mv old.txt new.txt
This command renames the file
rm is used to remove files or directories.
This command deletes the
cat is used to display the contents of files, concatenate files, and create new ones.
This command displays the content of
echo is used to output the text or value of a variable.
echo Hello, World!
This command will output the string “Hello, World!”.
grep is used for pattern searching in files using regular expressions.
grep 'text' file.txt
This command will search for the word ‘text’ in the file
file.txt and output the lines where the pattern is found.
chmod is used to change the permissions of a file or directory.
chmod 755 script.sh
This command changes the permissions
script.sh to 755 (read, write, and execute permissions for the user, and read and execute permissions for group and others).
sudo (superuser do) is used to execute a command with root privileges.
sudo apt-get update
This command updates the list of available packages and their versions but does not install or upgrade any packages.
The power of Linux lies in its command-line interface. Familiarizing yourself with these common commands is an essential step toward mastery. Remember, these commands only scratch the surface of what you can achieve with Linux, and there are countless more to explore. Happy learning!