Uploaded by Ghulam Hur

Linux Commands

advertisement
LAB 1 ASSIGNMENT
SUBMITTED TO: SIR NADEEM IQBAL
TASK 1:
You have to create 2 different text files. One with your name and the second one with your
registration no. Copy and paste some dummy data after that do the following task
1) Display the data of both files:
2) Display data page wise of both files:
(1)
(2)
3) Combine both files in new file.
TASK 2:
Try changing access permissions on the file os.txt.
SOME BASIC LINUX COMMANDS
1) Alias Command:
The command Alias is an amazing way to personalize and organize all your
commands. It allows users to designate a name to a single command or even a string of commands.
“alias wanted_name=command_name”
2) df Command
The df is a fundamental command on Linux. Using df, coders can display the size, available space,
and used space on the filesystems of the device. It comes with multiple options, such as the
following:
“df file_name.txt”












-a, –all : it includes duplicate and files that are inaccessible
-x: exclude specific filesystems
-i, –inodes: it list inode information rather than that of block usage
-T, –print-type: prints the type of file system
-P, –portability: it will use the POSIX output format
-B, –block-size=SIZE: increase the size before printing the result
-h, –human-readable: print sizes in power of 1024, which is Mb or Gb
-H, –si: shows result in the power of 1000
–total: omits all entries not relevant to available space, and presents the total
-t, –type=TYPE: the result is limited to listing to file systems of a particular type
–sync: invoke sync before the usage info
-l, –local: limit listing to local file systems
3) cal command:
Displays the calendar of the current month.
“$ cal”
‘cal ’ will display calendar for the specified month and year.
“cal month_number year”
4)date command:
Displays current time and date.
“$ date”
If you are interested only in time, you can use 'date +%T' (in hh:mm:ss)
“$ date +%T”
5) tty command
Displays current terminal.
“tty”
6) mkdir command
To create a directory, the ‘mkdir’ command is used.
“mkdir directory_name”
7) To remove or Delete
rmdir command removes any empty directories, but cannot delete a directory if a file is present
in it. To use ‘rmdir’ command, you must first remove all the files present in the directory you
wish to remove (and possibly directories if any).
“$ rmdir”
8) stat command
To check the status of a file. This provides more detailed information about a file than ‘ls l’ output.
“$ stat file_name.extension”
9) head command
Displays the first few lines of a file. By default, the ‘head’ command displays the first 10 lines of
a file. But with -n option, the number of lines to be viewed can be specified.
“head file_name.extenshion”
For number of lines to show:
“head -n no.of lines file_name.extenshion”
10) wc command
Word count
This command counts lines, words and letters of the input given to it.
“wc file_name.extenshion”
The file1.txt file has 2 lines, 11 words, and 63 letters present in it.
11) tail command
Similar to ‘head’; the ‘tail’ command shows the last 10 lines by default, and -n option
is available as well.
“tail file_name.extenshion”
For number of lines to show:
“tail -n no.of lines file_name.extenshion”
12) Pico & Nano
‘Pico’ is a text editor in Linux. ‘Nano’ editor is inspired from ‘pico’. They work almost the
same. If the argument given as filename exists, then that file will be opened for editing in
pico/nano. Otherwise, a new file with that name will be created. Let’s create a new file named
hello.txt:
“ pico file_name.extension”
Having made all the changes to the file, press ‘ctrl+o’ to write the changes to the file and ‘ctrl+x’
to exit from the editor. There are a lot of functions available with this editor. The help menu can
be accessed with ‘ctrl+g’ keystrokes.
13) last command
Displays information about the users who logged in and out of the system. The output of the last
command can be very large, so the following output has been filtered (through head) to display
the top 10 lines only:
“$ last”
14) expr Command
Expression command is used to calculate an expression as shown below.
“$ expr 20+30”
15) free Command
It shows the system memory usage (free, used, swapped, cached, etc.) in the system
including swap space. Use the -h option to display output in human friendly format.
“$ free -h”
16) mv Command
Move command(mv) is the command which moves a file to new destination.
“mv file_name new_file_name”
17) cp Command
Copy(cp) is the command which makes a copy of file1 in the current working Figure 12:
Combining a filedirectory and calls it file2.
“cp file1 file 2”
18) kill Command
The kill command is used to send a signal to processes. The most frequently-used signal is
SIGKILL or -9 which terminates the given processes.
Let’s say the Firefox browser has become unresponsive, and you need to kill the Firefox process.
To find the browser PIDs use the pidof command
“kill -9 $(pidof firefox)”
To get a list of all available signals, invoke the command with the -l option
“$ kill -1”
19) whatis command
This command gives a one line description about the command. It can be used as a quick
reference for any command.
“$ whatis command_name”
20) which Command
which command in Linux is a command which is used to locate the executable file
associated with the given command by searching it in the path environment variable.
“which filename filename2 …..”
which -a :
This option print all matching pathnames of each argument.
Download