This is the first online assignment for the Linux commands training module and in this assignment you will clone this repository to your local computer by doing the following:
- click the fork button
- Select your GitHub account as the desitnation to fork the repository
- Click the link to your newly forked repository
- Click the clone or download button
- Click the copy to clipboard button
- Open a terminal window
- Type git clone and then press command V to paste the clipboard url in your terminal
- Press enter
You will now practice the file commands in Linux using the newly cloned repo that will track your work.
Before you begin, set your current repository to a variable we can use later by typing repodir=`pwd`
Note: the symbol used here is the backtick and not the single quote. The backtick is next to the number 1 on your keyboard.
The man
command is used to display the manual for any Linux command. If you forget how to use a command in Linux you can simply type man
and then the command you want to read about. For example you can type man ls
to display the manual that describes the function and options for the list directory content command. You will use the man command in the further exercises of this module.
In a terminal window practice the present working directory command which is called pwd.
- In your terminal type the command pwd
- note that the terminal displays the current directory that you are working in
- Document your current directory by typing the command
pwd > pwd.txt
- Change directory to the root of your file system by typing
cd /
and then typepwd
- Change directory to the users directory by typing
cd /users
and then typepwd
- Type the command
cd $repodir
to return to your exercise directory
In a terminal window practice the change directory command which is called cd.
- Change directory to the root of your file system by typing
cd /
- Change directory to your Linux home drive by typing
cd ~
- Type the command
cd $repodir
to return to your exercise directory - Verify that you are in your exercise directory by typing
pwd >> pwd.txt
In a terminal window practice the list directory content command which is called ls.
- Type the command
man ls
and read the manual for the command
- pay particular attention to the options -l -t -r -a -h
- List the current contents of the directory you are located in by typing
ls
- List the current contents of the directory you are located by file creation date by typing
ls -ltr
- note that the files in your current directory are listed by date
- List the current contents of the directory you are located in by listing hidden files by typing
ls -lah
- note that the you now see more directories such as .git and .DS_Store
- List hidden files in the current directory by creation date by typing
ls -latr
- note that you see all files plus hidden files sorted by last modified date
- Type the command
ls -latr > ls.txt
to log your work to the file ls.txt for later review
In a terminal window practice the concatenate command which is called cat. Concatenate can display any human readable file such as a text file, a comma serperated values file or script.
- Type the command
man cat
and read the manual for the command - Display the content of the pwd.txt file to your screen by typing
cat pwd.txt
- see that the cat file displays on your screen the pwd.txt file you created in the present working directory exercise
- Type
cd /
and then typecat users
- note that you receive an error when trying to concatenate users because it is a directory and not a file
- Type the command
cd $repodir
to return to your exercise directory - Type
echo 'This is a test file' > test.txt
and then typecat test.txt
In a terminal window practice executing commands as another user by typing sudo. Sudo is a very powerful command that allows you to execute programs on a Linux system that are restricted to specific account with higher elevated rights.
- Type the command
man sudo
and read the manual for the command - Type the command
sudo su -
and type in your password
- note that your terminal now reads root because you have just switched to the root user account. Every command you type is executed as the root user and can be harmful if you are not careful
- Type the command
exit
to return to your regular user account
In a terminal window practice the general regular expression parser command by typing grep. Grep is a very powerful command that allows you to print lines from a file that match information you are searching for in human readable files. This command is often used to search for and identify patterns in a file or count lines in a file. The uses of the grep command are extensive.
- Type the command
man grep
and read the manual for the command - Type the command
grep we gettysburg-address.txt
- note that your terminal returns every line in the file that includes the word we
- Now type the command
grep -i we gettysburg-address.txt
and press enter
- note that your terminal returns every line in the file that inclues the word we and We because the -i option turns on case insensitivity for grep
- Now type the command
grep -in we gettysburg-address.txt
and press enter
- note that the line number on which the word we is listed before each line returned
- Now type the command
grep -ic we gettysburg-address.txt
and press enter
- note that the number of times the word we or We is in the Gettysburg Address is counted
- Now type the command
grep -in 'it' * > grep.txt
and press enter
- note that grep has searched every file in the current directory for the word it and returned output showing the file and line number it found it on