In: Computer Science
Lab 1-Refreshing Linux basics
Objective: (Complete using Netlab)
Please try each command in Linux system, and get screenshots (you may put multiple commands in one screenshot) which can show how actually each command runs. Also, give a brief description (one or two sentences) for each command. For the commands which have multiple switches/parameters, please try one popular switch/parameter.
If after the command, there is “date”, please run date to show the system date and time before you run the command; but if there is “name”, please type your first and last name, such as “Levis (First name) Johnson (Last Name)” before you run this command. Your screenshot must include the above information.
Linux Commands
grep (date), find, man, ls , chmod, chown (name), passed, useradd and adduser, su, vi, rmdir (date), wherein, lsmod, insmod (name), make, | pipe, ln, rm, cp, mv, (name), ld, ftp, more, less, cat (date), tar, top , ps (name), kill, df, last, patch, mkdir (date)
1. Grep( date ) :
grep "$(date +"%Y-%m-%d")" file
2.Find
find [where to start searching from] [expression
determines what to find] [-options] [what to find]
eg: find ./GFG -name sample.txt
3.Man
The man command displays the “man pages” for a command in less .
The man pages are the user manual for that command. Because man
uses less to display the man pages, you can use the search
capabilities of less.
For example, to see the man pages for chown, use the following command:
man chown
Use the Up and Down arrow or PgUp and PgDn keys to scroll through
the document. Press q to quit the man page or pressh for help.
4. ls
This might be the first command the majority of Linux users meet. It lists the files and folders in the directory you specify. By default, ls looks in the current directory. There are a great many options you can use with ls , and we strongly advise reviewing its the man page. Some common examples are presented here.
To list the files and folders in the current directory:
ls
To list the files and folders in the current directory with a
detailed listing use the -l (long) option:
ls -l
To use human-friendly file sizes include the -h (human) option:
ls -lh
To include hidden files use the -a (all files) option:
ls -lha
5. chmod
The chmod command sets the file permissions flags on a file or folder. The flags define who can read, write to or execute the file. When you list files with the -l (long format) option you’ll see a string of characters that look like
-rwxrwxrwx
If the first character is a - the item is a file, if it is a d the
item is a directory. The rest of the string is three sets of three
characters. From the left, the first three represent the file
permissions of the owner, the middle three represent the file
permissions of the group and the rightmost three characters
represent the permissions for others. In each set, an r stands for
read, a w stands for write, and an x stands for execute.
If the r, w, or x character is present that file permission is granted. If the letter is not present and a - appears instead, that file permission is not granted.
One way to use chmod is to provide the permissions you wish to give to the owner, group, and others as a 3 digit number. The leftmost digit represents the owner. The middle digit represents the group. The rightmost digit represents the others. The digits you can use and what they represent are listed here:
0: No permission
1: Execute permission
2: Write permission
3: Write and execute permissions
4: Read permission
5: Read and execute permissions
6: Read and write permissions
7: Read, write and execute permissions
Looking at our example.txt file, we can see that all three sets of
characters are rwx. That means everyone has read, write and execute
rights with the file.
To set the permission to be read, write, and execute (7 from our list) for the owner; read and write (6 from our list) for the group; and read and execute (5 from our list) for the others we’d need to use the digits 765 with the chmod command:
chmod -R 765 example.txt