Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created May 1, 2012 08:25
Show Gist options
  • Save ynonp/2566283 to your computer and use it in GitHub Desktop.
Save ynonp/2566283 to your computer and use it in GitHub Desktop.
Unix Ex1

Part 1

  1. Use uname to get details on your machine. What is your kernel version ?

  2. What is your default shell ? What version is it ?

  3. Find a list of all connected users to your server

  4. Run ifconfig to get information about network connections. Did it work ?

  5. Try to find ifconfig in the system. Hint: It's a system binary

  6. Use date to show the current time formatted HH:MM:SS (Hint: man date)

Part 2

  1. Create the directory Data and inside the files: data1, data2, data_3, .data, my_name

  2. Create the directory Zoo and inside the files: keeper, animals, Visitors

  3. Create the directory Progs and inside the files: ‫‪ prog1.c,prog2.c,small_prog,medium_prog,.pro1.exe,my_prog‬‬

  4. Create the directory Family inside the Zoo directory

  5. Create a file named My_name and write your name in the first line and city in the second

  6. Create a file named My_family and write the names of 3 family members - each in their own line

  7. Verify all files are under the Family directory

  8. Copy the file My_name to a file named name

  9. Rename the file My_family to Family

  10. (Bonus) Create a file called Whole_family that contains the contents of both Family and name

  11. Display the contents of Whole_family

  12. Go back to your home directory

  13. Rename the Zoo directory to My_zoo

  14. Copy the Family directory and all its contents to your home directory

  15. Delete the directory My_zoo

  16. Create two files inside /tmp named after you

  17. Calculate the size of your home directory using: du -shL ~

Part 3 - Wildcards

  1. Copy all the files (without directories) from Family which start with a letter, into a new directory called Capital in your home directory

  2. Use ls -ld to display all files that have an _ in their name under Progs directory

  3. Delete all files that end with a .c in Progs directory

  4. Display all files beginning with data under Data directory

  5. Delete all files starting in My or my

  6. Display all files whose name ends with a digit, under directories whose name starts with P or D. For example, Progs/cool7 should be displayed.

  7. Braces are used to create multiple files and folders in a single command line. Run the following: mkdir -p day_{one,two,three}/{basic,mid,advanced}_group How many directories were created ?

Part 4 - Vim

You can use Vim Cheat Sheet for a short reference on vim commands.

  1. Modify ~/.itools to use the newest vim version (7.3)

  2. Copy the file /etc/passwd to a new file named passwd.new in your home directory

  3. Type the following lines in the beginning of the new file:

     # This is a backup for user admin file /etc/passwd
     # Author: Luke Skywalker
     # Author's Father: Darth Vader
    
  4. Go to line 10 and copy it to the beginning of the file

  5. Replace all occurrences of the word csh to bash

  6. Delete line 6

  7. Add line numbers to the file

  8. Move line 7 to appear before line 4

  9. Save the first 10 lines to a new file named pass.new2

  10. Save and quit

  11. Open both files in the same vi session. Cut the first 3 lines from pass.new and paste them into pass.new2

  12. Save the world: vim-adventures

Part 5 - Permissions

  1. Create a directory named lock in your home directory and inside create a file named tmp_file. Write your name into the file

  2. Go back to your home directory and grant read only permissions on lock to all users

  3. Edit the file tmp_file in lock directory, add your city in a new line. Did it work ?

  4. Change symbolically (using letters) the permissions for all files inside Progs directory to: rw-r--r-w, without changing the permissions for the directory itself.

  5. Change absolutely (using numbers) the permissions for all files inside Data directory to read/write for user, read for group, executable for others.

  6. Revoke all permissions from Progs folder

  7. Move Progs folder and all its files into Data. Did it work ?

Part 6 - Links

  1. Create a directory named links and enter it.

  2. Create a file named file1 with the line: this is file1

  3. Create a file named file2 with the line: this is file2

  4. Create a hard link named file3 to file1

  5. Create a symbolic link named file4 to file2

  6. In your home directory, create a link named Link_to_links to links directory

  7. Use cat to watch the four files

  8. Remove file1 and watch the contents of file3

  9. Remove file2 and watch the contents of file4

  10. Create file2 again using: cat /etc/passwd > file2

  11. Watch the contents of file4

Part 7 - Redirections

  1. redirect the output of ls -Rl -L ~ to a file named list

  2. Did you get any errors ? Run the same command again, this time redirecting the errors to a file named LsErr

  3. Move the contents of LsErr to the end of list

  4. Prevent the shell from clobbering files

  5. Perform command from (1) again so it will clobber the file list

Part 8 - Pipes & Filters

  1. Display the number of files (including directories and links) that have execute permissions for others.

  2. The command rpm -qa shows all software installed on the system. Count the numebr of software packages installed.

  3. How can you verify the mozilla program is installed ?

  4. Display the total number of files under all subdirectories in your home folder (only the files)

  5. Display the number of files modified today ( use a specific date )

  6. Use cal commnad to create a file named Sat that contains all dates of Saturdays in May 2004

  7. Use mail to send Sat file contents to your personal mailbox: cat Sat | mail -s "May 04 Saturdays" YOUR_EMAIL@ADDRESS

  8. Display the largest 3 files in your home directory.

  9. Check how many files have execute permissions to everyone.

Part 10 - Regular Expressions

  1. Redirect the output of ls -lR to a file named Temp_RE

  2. Find all lines which start with a "d"

  3. Find all lines which end with a "y"

  4. Find all lines which contains a digit

  5. Find all lines which start with an l, a -, or a .

  6. Find all lines which start with a "-" and contains an "n"

  7. Find all lines which contains an "o" followed by a "u"

  8. A file or directory that has permissions 777 is considered at risk. Locate in all folders under your home directory the list of files in at risk. Store the list in a file named Permissions_Log

  9. Find all lines which contains up to 70 characters

  10. Find all lines which contains exactly 60 characters but no "."

Part 11 - Find

  1. Display the number of files (no directories)

  2. Display the number of links

  3. Display files (without directories) larger than 20k

  4. Display files whose name ends with a ".c". Format the output like ls -l

  5. Delete all files you own under /tmp

  6. Display files (without directories) which were updated in the last 4 hours.

  7. Find all .cpp files which contain the word main

  8. Find all files which contain at least one line that starts with "#"

  9. Find all files which does not contain any digits and print their names

Part 12 - Environment

  1. Create the following files:
  1. a b c
  2. a* b*c
  3. .a? b\ c
  1. Define the following aliases:

     rm => rm -i
     cp => cp -i
     c  => clear
    
  2. Create an alias to add executable permission to a file

  3. Saving aliases is performed by storing them in a special file. Add the aliases you created to your .aliases file

  4. Login again and check the aliases were created

Part 13 - Processes

  1. Use less /etc/passwd to show the contents of the file. Leave it open.

  2. In a new shell window, locate all your processes using ps au. What is the process number of the less command from (1) ?

  3. Execute ls -lR / and freeze it immediately using Ctrl+Z

  4. Use jobs to find the job number

  5. Resume the process using fg. It's ok to end it now with Ctrl+C

  6. Run the following process: /tmp/demo.pl &

  7. Can you stop the process using Ctrl + C ?

  8. Use the special kill to terminate the demo process

  9. Use at to perform the following and email the results:

  1. Display all executable files at 14:00
  2. Backup .aliases at 19:00
  3. Send "Go Home" email at 17:00

Part 14 - Git

  1. Create a new git repository and add the following 2 files:

colors.txt

numbers.txt

  1. Write some colors into colors.txt, and some numbers into numbers.txt

  2. Check the repository's log file. What is the commit number ?

  3. Create the following empty files: data1, data2, data3 - and add them to the repository in a commit

  4. Check the repository's log file. What is the commit number ?

  5. Create the following two empty files: prog1.c, prog2.c, and add them to the repository in two separate commits

  6. Modify numbers.txt by adding some more numbers to it. Display the difference between the new file and the saved one.

  7. Discard your changes and go back to the saved copy

  8. Add some colors into colors.txt, and write your name into data1. Commit your changes

  9. Restore the state of the entire project to go back to step 1, step 3, and then back to head

Part 15 - awk

  1. Count all non-blank input lines

  2. /sbin/ifconfig prints out information about network interfaces. Use awk to extract your server's IP addresses from the output

  3. Use who and awk to show only user names connected today

  4. Print all file names whose size is larger than 500

  5. Extract from /etc/group all group names which have more than 4 users in them

  6. man -k word shows all man pages related to word. Each output line has the man page name, the man section, and a description. Show only man pages from section 3 related to word ls

  7. Show only shells from /etc/shells installed in folder /bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment