Linux common Commands
To view help about command
Command: man command_name
Creating file with touch
Command: touch "file name"
Example : touch "application properties"
Creating file with Contents
Command: cat > file_name press enter button
Type file contents
Close it with ctrl+Z
Creating Directory command
Command: mkdir directory_name
Creating more than one directory
Command: mkdir directory1 directory2
View current user info
Command: who am i
View Present working directory
Command: pwd
View System time
Command: date
View current month calender
Command: cal
Shifting LINUX terminal with commands
It has seven terminals( 6 - CUI terminals, 1 - GUI terminal)
Commands: chvt 1 Short cut: ctrl + alt + F1
chvt 2 ctrl + alt + F2
chvt 3 ctrl + alt + F3
chvt 4 ctrl + alt + F4
chvt 5 ctrl + alt + F5
chvt 6 ctrl + alt + F6
GUI Terminal: chvt 7 ctrl + alt + F7
Shut down
Command : init 0
Creating Hidden Files
Command: touch . filename
Creating Hidden Directory
Command: mkdir . directory_name
Creating hierarchy of directories
Command: mkdir -P directory1 | directory2 | directory3
View file contents
Command: cat filename
Viewing Present working directory contents
Shows the files in the present working directory
Command: ls
Long listing of the files and directories in the present working directory
Command : ls -l
View all files including hidden files
Command: ls -a
Long listing of the files including hidden files
Command: ls -al
Recursively displays directories and sub directories
Command: ls -R
Command: ls ?some_text
Command: ls *some_text
Ranging specifying
Command: ls [a-d]some_text
Command: ls [^a-d]some_text
Changing directory
Moves one directory up
Command: cd ..
Three steps back (Some steps back)
Command: cd ../../..
Three steps to front (Some steps to front)
Command: cd directory_name1/directory_name2/directory_name3
Going back to home directroy
Command: cd ~
Going back to previously working directory
Command: cd -
Deleting empty directory
Command: rmdir directory_name
Deleting non-empty directory
Command: rm -r directory_name
Deleting file
Command: rm filename
Moving file(Cut and paste)
Command: mv source destination
Renaming file
Command: mv old_file_name new_file_name
Copy file
Command: cp source_file_path destination_path
Searching text in file
It is used to search a particular text in a file or in a directory
Command: grep some_text file_name
To search text in present working directory
Command: grep some_text .
Command: grep some_text directory_name
Creating user
Command: useradd user_name
Command: passwd user_name
Deleting user
The following command deleted user but does not delete directory from home directory
Command: userdel user_name
To delete user along with the directory at home
Command: userdel -r user_name
Process Killing
Command: kill i_node_number
To view current list of users logged in along with personal information
Command: finger
Changing Permissions after creating file
The following command gives permissions read, write and execute to owner, group and others
Command: chmod 777
Example to give write permissions to user
Command: chmod u+w
Example to remove write permissions to user
Command: chmod u-w
Example to give write permissions to group
Command: chmod g+w
Example to remove write permissions to group
Command: chmod g-w
Example to give write permissions to others
Command: chmod o+w
Example to remove write permissions to others
Command: chmod o-w
To view all previously executed commands
Command: histroy
To display first n number of lines of the file
Command: head -n file_name
Example: head -2 file_name
It displays first two lines of the file
To display last n number of lines of the file
Command: tail -n file_name
Example: tail -2 file_name
It displays last two lines of the file
Displaying multiple files simultaneously
Command: pate file_name_1 file_name_2 file_name_3
Translate
Command: tr 'a-z' 'A-Z' file_name
Sorting file contents
Command: sort file_name
Going to other shell
Simply type shell name : sh
ksh
df –h command
It displays - device name,
total blocks, total disk space, used disk space, available disk space and mount
points on a file system.
-h Human Readable format
su - substitute
user or switch user
su – another_user
ps -command
This command is used to
view processes running on the system.
Examle : ps –ef | grep
apache
chown
chown chnages owner or group ownership.
Examples:
1 1) home/abc_dir$
chown new_owner_user helloworld.txt
the above command changes holloworld.file owner to “new_owner_user”.
2
2)
home/abc_dir$ chown new_owner_user *
The above command changes contes of abc_dir and sub folders
owner to “new_owner_user”.
3
3)
home/abc_dir$ chown new_owner_user:web_group helloworld.txt
the above command changes holloworld.file owner to “new_owner_user”
and owner group to “web_group”.
4
4)
home/abc_dir$ chown new_owner_user: web_group *
The above command changes contes of abc_dir and sub folders
owner to “new_owner_user” and owner group to “web_group”.
Vi Editor commands:
It opens existing file, if file exists other wise it creates.
vi file_name
Following commands opens file in read mode
vi –R file_name
view file_name
Closes file after writing changes to file.
:wq!
Closes file without writing changes to file.
:q!
Moves cursor to starting of the current line if file is not in insert mode.
0
Moves cursor to end of the current line if file is not in insert mode.
$
x - removes one character in command mode.
Running shell script:
It runs specified shell script file.
Syntax 1: ./file_name.sh
Syntax 2: sh file_name.sh
Locate Linux command:
This command is used to find the locations of files and
directories in Linux.
Syntax:locate options names
Example 1: locate abc.png
The following example displays only screenful of
output at a time.
Example2: locate "*.html" | less
nslookup(name server lookup) command:
Syntax: nslookup domain_name
Example: $ nslookup csesss-lx00034
It transforms domain name to IP address.
more command:
It shows first page contents.
Syntax: more file_name
press space bar to view next page contents.
press enter to view next line contents.
Vi Editor commands:
It opens existing file, if file exists other wise it creates.
vi file_name
Following commands opens file in read mode
vi –R file_name
view file_name
Closes file after writing changes to file.
:wq!
Closes file without writing changes to file.
:q!
Moves cursor to starting of the current line if file is not in insert mode.
0
Moves cursor to end of the current line if file is not in insert mode.
$
x - removes one character in command mode.
Running shell script:
It runs specified shell script file.
Syntax 1: ./file_name.sh
Syntax 2: sh file_name.sh
No comments:
Post a Comment