Basic Linux Commands
Table of contents
Introduction to Linux
Linux is an open-source operating system kernel.It is suitable for diverse environments.
It has a powerful command-line interface (CLI) alongside user-friendly graphical interfaces.
Multiuser and Multitasking: It supports multiple users and tasks running concurrently. This makes it suitable for servers, where many users might need access, and for desktops, which require multitasking capabilities.
Security: Linux's open-source nature facilitates security audits and timely updates.
Variety of Distributions: Some popular ones include Ubuntu, Fedora, Debian, CentOS, and Arch Linux.
Package Management: Linux distributions use package management systems (e.g., APT, YUM, and Pacman) to facilitate the installation, removal, and updating of software.
Linux is a popular choice for servers, embedded systems, and personal computers.
Linux has GPL :General Public License
It focuses on shell scripting,networking, terminal,programming.
It is secure.
Updates are less than window
Some linux basic commands
File and Directory Management
**ls (list) :**List all contents (files and directories) in the current directory.
ls-h:
Human-readable file sizes.ls -a
: List all files and directories, including hidden ones.ls -l
: List files and directories in detailed format.ls -t
: List files and directories sorted by modification time.ls -rt
: List files and directories in reverse order of their names
pwd (print working directory) : Print the name of the directory that the user is currently working in.
**cd(change directory):**allows the user to change to a specified directory.
mkdir(make directory): allows the user to create a new directory..
Usage: mkdir directory_name
Along with mkdir we can use the "-p" flag which will create sub-directories (directories within a directory) if it does not exist.
touch :Create an empty file.
- Usage: touch file_name
cp :Copy files or directories.
Usage: cp source_file destination_directory
cp -r: Copy directories recursively.
mv :Move or rename files or directories.
- Usage:mv source_file destination
rm (remove): Remove files or directories.
Usage: rm file_name
rm -r: Remove directories recursively.
With this command, we can use the "-r" flag, which removes the files recursively within a directory but do not use "-rf" which will forcefully delete the files and will not give a prompt when deleting important files.
File viewing and Editing
cat(concatenate): Display the contents of a file.
- Usage: cat file_name
more and less Display file contents one screen at a time.
- Usage: more file_name & less file_name
head and tail Display the beginning or end of a file.
- Usage: head file_name & tail file_name
grep Search for text in files using patterns.
- Usage: grep "pattern" file_name
File permission and ownership
chmod :Change file permissions.
Usage: chmod permissions file_name
ls -l : to see permission of file or dir
chown command : change ownership
Process Management
ps : List running processes.
kill: Terminate processes.
- Usage: kill PID
top: Display active processes in real-time
man :Access the manual pages for commands.
- Usage: man command_name
System Information
df: Display disk space usage
du: Display file and directory space usage
lscpu :Display CPU
Compress and archieve
tar: Archive and compress files.
Usage: tar options archive_name files/directories
-c: Create a new archive.
-z: Compress the archive using gzip.
wget : Download files from the internet.
- Usage: wget URL
Network Commands:
ping: Check network connectivity to a specific host.
ifconfig or ip: Display network interface information.
Administrative Tasks
whoami:displays the username of the current user when this command is entered.
Sudo:execute commands with administrative privileges
grep <search_word> <filename> //searches for word in a file
-i overlook case sensitivity
-R looks through dir as well.
-v reverse search, searches everything except given search word
sed /s/<search-word>/<reaplce_word>/g //sed allows editing of file without opening it
/s search
/g global
less <filename> // reads file without allowing to edit. (readonly)
Subscribe to my newsletter
Read articles from Ruchi Lamichhane directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ruchi Lamichhane
Ruchi Lamichhane
I am a tech ethusiast with passion for technology, embracing the world of continuous integration, automation, and collaboration to make a meaningful impact in the dynamic realm of DevOps.