0% found this document useful (0 votes)
2 views

Basic Linux Commands

This document provides a comprehensive guide to basic Linux commands, covering system information, file and directory management, user and group administration, file permissions, process management, disk management, and networking commands. Each section includes specific commands along with their usage and examples. It serves as a quick reference for users to perform various tasks in a Linux environment.

Uploaded by

amr77eldeeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Basic Linux Commands

This document provides a comprehensive guide to basic Linux commands, covering system information, file and directory management, user and group administration, file permissions, process management, disk management, and networking commands. Each section includes specific commands along with their usage and examples. It serves as a quick reference for users to perform various tasks in a Linux environment.

Uploaded by

amr77eldeeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Basic Linux commands

System Information

Show computer architecture:

arch

Show kernel version

uname -r

Show system date

date

Show calendar table for 2014

cal 2014

Files and Directories

Go to '/var/www/'

cd /var/www

Go to the upper level directory

cd ..

Go to home directory

cd ~

Go to home directory of “user”

cd ~user

Show the contents of the current directory

ls

Show the contents of the current directory adding characters to the names characterizing the type

ls -F
Show detailed representation of files and directories in the current directory

ls -l

Show hidden files and directories in the current directory

ls -a

Create a directory called ‘test’

mkdir test

Create two directories simultaneously

mkdir test1 test2

Create a directory tree

mkdir -p /var/www/test/dir

Delete the file named ‘file’

rm -f file

Delete a directory named ‘dir’

rmdir dir

Delete a directory named ‘dir’ and all of its contents recursively

rm -rf dir

Rename or move a file or directory

mv dir1 new_dir

Copy file1 in file2

cp file1 file2

Create a symbolic link to a file or directory

ln -s file1 file2

Searching Files
Find files and directories named file1. Start searching from the root (/)

find / -name file1

Find files and directories owned by user1. Start searching from the root (/)

find / -user user1

Find all files and directories whose names end in ‘.log’. Start searching from ‘/var/www’

find /var/www -name "*.log"

Find all files containing '.png' in the name. it is recommended to run 'updatedb' command before
this.

locate "*.png"

Find all files with '.log' extension in the current directory, including subdirectories and delete
them

find . -name '*.log' -type f -delete

Disk Space

Information about partitioned sections displaying total, free and used space

df -h

Show the size used by directory ‘dir1’

du -sh dir1

Users and Groups

Create user1, assign /home/user1 as its home directory, assign /bin/bash as a shell, include it in
‘admin’ group and add a comment Nome Cognome

useradd -c "Nome Cognome" -g admin -d /home/user1 -s /bin/bash


user1

Create user1

useradd user1

Delete user1 and its home directory


userdel -r user1

Create a new group named group_name

groupadd group_name

Delete group group_name

groupdel group_name

Rename group old_group_name in new_group_name

groupmod -n new_group_name old_group_name

Change password

passwd

Change password of user1 (only root)

passwd user1

Setting/Changing File Rights

Add rights 777 (Read Write Execute) to directory1 – full rights to everybody.

chmod 777 directory1

Add rights to directory1, including all files and subfolders in it, rights 777 (Read Write Execute)
- full rights to everybody.

chmod –R 777 directory1

Assign user1 as the owner of file1

chown user1 file1

Recursively assign user1 as the owner of directory1

chown -R user1 directory1

Assign user 'apache' from the group 'apache' to folder 'dir', including all subfolders and files:

chown apache:apache -R /var/www/dir

Find all files in the current directory, including subfolders and assign rights 664
find . -type f -printf "\"%p\" " | xargs chmod 664

Find all folders in the current directory, including subfolders and assign rights 775

find . -type d -printf "\"%p\" " | xargs chmod 775

File Archiving and Compression

Unarchive file 'file1.bz2'

bunzip2 file1.bz2

Unarchive file 'file1.gz'

gunzip file1.gz

Archive file 'file1' to file1.gz

gzip file1

Archive file file1 to file1.bz2

bzip2 file1

Create an archive and zip it with gzip

tar -cvfz archive.tar.gz dir1

Unarchive and extract

tar -xvfz archive.tar.gz

Create zip-archive

zip file1.zip file1

Unarchive and extract zip-archive

unzip file1.zip

Upgrading Packages

Upload and install package

yum install package_name


Update all packages installed in the system

yum update

Update package

yum update package_name

Delete package

yum remove package_name

Show the list of all packages installed in the system

yum list

Find a package in the repository

yum search package_name

Clean rpm-cache, deleting uploaded packages

yum clean packages

Clean rpm-cache, deleting uploaded packages and headers

yum clean all

Help Commands

It is used to find concise descriptions of system commands by searching the Whatis


whatis
database for entire words.
which Displays full path to shell commands
whereis Search and discover command's binary, source, and man pages
Look for help and man pages containing specific phrases and instructions by searching
apropos
a database of short descriptions.
man Lists Manual pages for the respective command

File Operations

cat Concatenate files or print a file on the monitor.


touch Make a new file and modify the timestamps.
cp Copy files or directories.
mv Moves files or directories.
rm Removes directories or files in a recursive manner
ln It is used for creating a symbolic or hard link for a file.
less Viewing a single file on a single page, along with the ability to go backwards.
head Printing the first ten lines of a file.
tail Printing the last ten lines of a file.
wc Counts the total number of words or characters there are in a file.
stat Shows the status of a file or a file system.
cut Remove parts of input lines.
paste Combine multiple lines of text in a single file.

Process Management

ps Provide an update on existing procedures.


pstree Displays a tree of processes.
top Demonstrate real-time procedures.
kill PID is used to terminate a process.
killall Stop a process permanently via name
pkill Looking up for processes or signals based on the same and other attributes.
pgrep Look for information on the process.
ctrl+z Stop the task instead of keeping it on halt permanently.
& The addition of this after a command puts the process in the background.
jobs Displays all the jobs running in process

Partitions and Disk Management

df Report on the amount of disc space used by the file system.


mount Mount a file system or see what's mounted.
unmount Unmounts a file system
fuser Identifies processes via files or sockets.
isof Displays a list of the system's open files

Accounts and Security Administration

groupadd Used for creating new groups


groupdel Used for creating groups
groupmod Manipulating the description of a particular group
useradd Creating new users
userdel Deleting new users
usermod Modifying a user’s account
passwd Updating a user’s password
vipw Editing the password or shadow password of a group
vigr Editing groups or shadow groups
chage Modifying password policies

Networking

ifconfig Set up the network interface.


route Shows and manipulates IP routing table
Replaces ifconfig, arp, and route by displaying and manipulating routing, devices,
ip
policies, and tunnels.
ifup It brings up the network interfaces
ifdown It brings the network interfaces down
ping Sends ICMP ECHO_REQUEST to network hosts

Directory Operations

clear Removes all the contents from your screen


pwd Displays running directory on the screen
cd Modifies directories
ls Lists down all the content of a directory
mkdir Creates a new directory
rmdir Deletes null directories

You might also like