Linux Shell Commands - Tutorial 1


Check your current directory:
	pwd
Change to the root directory of the file system:
	cd /
Verify your current directory:
	pwd
List directories at the filesystem root:
	ls
List all the system configuration files in the 'etc' directory:
	ls etc
List directories under the 'usr' directory:
	ls usr
List system include files in /usr/include:
	ls usr/include
List system command files in /usr/bin:
	ls usr/bin
List home directories under /users:
	ls users
Move to your home directory:
	cd ~
Verify your current directory:
	pwd
List the files already here, if any:
	ls
Create a subdirectory to temporarily test some commands in:
	mkdir test
Change down a level into the test subdirectory:
	cd test
List the files here, empty since we just created it:
	ls
The 'echo' command just sends its command line arguments to standard output:
	echo Dedman Fondren Heroy Dallas
Redirect the output of the 'echo' command into a file:
	echo Dedman Fondren Heroy Dallas > test1
See that the file was created in the current directory:
	ls
Show the type of the file just created:
	file test1 
Display the file contents:
	cat test1 
Copy the contents to another file, 'test2':
	cp test1 test2
List the files now in the current directory:
	ls
Display the contents of the new copied file:
	cat test2
Concatenate the two files and display the result:
	cat test1 test2
Use the 'mv' command to change the name of 'test2' to 'test3':
	mv test2 test3
List the files now present:
	ls
Verify the contents of the renamed file:
	cat test3
Display the current date and time:
	date
Redirect the output of the 'date' command into a file
	date > test4
List the files now present:
	ls
Display the contents of the new file:
	cat test4
Generate some more words of text:
	echo McFarlin Daniel Airline Dyer
Now redirect the 'echo' command output and append it to an existing file:
	echo McFarlin Daniel Airline Dyer >> test1
Check the contents of the file:
	cat test1
Append some other words to another file:
	echo Bishop Ownby Binkley >> test4
Append the name of the current working directory to the file as well:
	pwd >> test4
Check the contents of the file:
	cat test4
Check the expansion of a file "globbing" wildcard character:
	echo test?
Check the expansion of another file "globbing" wildcard character:
	echo t*
Concatenate the contents of all the files:
	cat t*
Display the line, word and character count in a file:
	wc test4
Display the file listing in long format:
	ls -l test4
Total the word count in all the files:
	wc test?
Concatenate the contents of all the files and count the resulting words:
	cat test? | wc
Create another subdirectory:
	mkdir junk1
Make it the current working directory:
	cd junk1
Verify the current directory:
	pwd
Generate some text in a file by copying a system configuration file:
	cp /etc/services test1.txt
Check the history of commands entered in this shell:
	history
Generate another text file by redirecting the output of 'history':
	history > test2.txt
Redirect some keyboard input into the 'cat' command, into its standard input and through its standard output, to a third text file, control-D key will terminate:
	cat > test3.txt
Display the contents of the third text file:
	cat test3.txt
Check the files created in the current directory, and list their sizes:
	ls -l
Get total word counts for the files:
	wc *.txt
Browse through the first large text file:
	less test1.txt 
Browse through the second large text file:
	less test2.txt 
Display all lines in the first file containing the text 'http':
	grep http test1.txt
Display all lines in the first file containing the text 'server':
	grep server test1.txt
Browse through all lines in the first file containing the text 'server':
	grep server test1.txt | less
Display the top of the first text file:
	head test1.txt 
Display the bottom of the first text file:
	tail test1.txt 
Display all the 'echo' commands previously entered:
	grep echo test2.txt
Count the number of 'echo' commands previously entered:
	grep echo test2.txt | wc
Another way to count the number of 'echo' commands previously entered:
	grep -c echo test2.txt 
Change directory to one level up:
	cd ..
Verify what the current directory is:
	pwd
List the contents here:
	ls
Create another temporary subdirectory:
	mkdir junk2
Show the new subdirectory was created:
	ls
List the text files one level down in the first subdirectory:
	ls junk1
Use the 'mv' command to move the text files from the first to the second subdirectory:
	mv junk1/*.txt junk2
Verify the files are in the second subdirectory:
	ls junk2
Show the first subdirectory is now empty:
	ls junk1
Remove the first subdirectory:
	rmdir junk1
Check the result status of the 'rmdir' command:
	echo $?
Try removing the second subdirectory:
	rmdir junk2
Check the result status of this 'rmdir' command:
	echo $?
Delete all the files in the second subdirectory:
	rm junk2/*
Now remove the second subdirectory:
	rmdir junk2
Check the result status of this 'rmdir' command:
	echo $?
See what is left in the current directory:
	ls
Move one directory level up to your home directory:
	cd ..
Use the 'mv' command to rename the temporary subdirectory:
	mv test work
Check the results of the directory rename:
	ls
Try removing the temporary subdirectory:
	rmdir work
Delete all the files in the temporary subdirectory:
	rm work/*
Now remove the temporary subdirectory:
	rmdir work