0% found this document useful (0 votes)
5K views2 pages

Linuxgym Answers

This document provides instructions for completing various file system tasks using common Linux commands like touch, mkdir, ls, cat, head, cp, and more. It describes how to 1) create and view files, 2) create directories, 3) store calendar output in a file, 4) list visible and all files in a directory and store in files, 5) view the top of a file using head, 6) merge files contents, and 7) copy the smallest file from one directory to another. The commands demonstrated include touch, mkdir, ls, cal, cat, head, and cp.

Uploaded by

thepaperkrain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5K views2 pages

Linuxgym Answers

This document provides instructions for completing various file system tasks using common Linux commands like touch, mkdir, ls, cat, head, cp, and more. It describes how to 1) create and view files, 2) create directories, 3) store calendar output in a file, 4) list visible and all files in a directory and store in files, 5) view the top of a file using head, 6) merge files contents, and 7) copy the smallest file from one directory to another. The commands demonstrated include touch, mkdir, ls, cal, cat, head, and cp.

Uploaded by

thepaperkrain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 1: files, Directories and Redirection File system commands: ls , mkdir, cd, pwd, cp, mv, rm Viewing files:

cat, less, head, tail commands and their options: touch, cal, wc (the hash is followed by the command, example #<command) 1. create a file Create a file called "hello.world" (without quotes). Hint: touch #touch hello.world 2. create a directory Create a directory called "otherworld" (not including the quotes). #mkdir otherworld 3. Store a calendar Store the 2008 calendar produced by the 'cal' command in the file 'calendar' with no modifications to the output of the 'cal' command. Hint: standard output redirecting using '>' #cal 2008 > calendar 4. List visible files List all (non-hidden) files in the directory '/usr/local/linuxgym-data/gutenberg' and store this list into a file called 'listvis'. Ensure that this is exactly the output of the command 'ls' #ls /usr/local/linuxgym-data/gutenberg > listvis 5. List all filese By 'all files' we refer to every file which is not a directory, including hidden files whose names begin with ".". List all files in the directory 'usr/local/linuxgym-data/gutenberg' and store this list into a file called 'allfiles'. Ensure that this is exactly the output of the command 'ls'. (Hint: consider 'all' and 'almost-all' options in the 'man ls' command). #ls -a /usr/local/linuxgym-data/gutenberg > allfiles 6. Top of a file The 'cat' function prints out the contents of a file. For example 'cat /usr/local/linuxgym-data/census-aj_malenames.txt' shows you alphabetically ordered list of male names recorded by the US census bureau. Because the list scrolls off the top of the screen, you cannot easily read the first 10 names. The 'head' command solves this problem. Experiment with the 'head' command and store the first 10 lines from the file a-j_malnames.txt into a file called 'first-ten-names.txt' (hint: redirect the output using '>') #head -n 10 /usr/local/linuxgym-data/census/a-j_malenames.txt > ten-names.txt // -n :number of lines 7. Merging Files The 'cat' function which prints out the contents of a file, can be used to print the contents of several files by giving it more than one argument. In the directory /usr/local/linuxgym-data/census/ there are two files: a-j_malenames.txt and k-z_malenames.txt. Use 'cat' to print out both of these files and store the output in a file called 'a-z_malenames.txt' in the correct order. (Hint: redirect the output using ">") cat /usr/local/linuxgym-data/census/a-j_malenames > a-z_malenames.txt

cat /usr/local/linuxgym-data/census/k-z_malenames >> a-z_malenames.txt // >> : merge with exisiting content 8. File size Look at the files in the directory /usr/local/linuxgym-data/teeny and identify which is the smallest file. Copy this file into your ch1-fdr directory. (hint: cp, ls -1) ls -1 -s /usr/local/linuxgym-data/teeny (or ls -1 -s -S) cp /usr/local/linuxgym-data/teeny/filename // filename (smallest) to /home/student/..

You might also like