Short Self-Test Questions on Unix

How to identify whether a file is normal file or directory? 

$ls -l filename/directoryname
if the first digit is - then it is file,
if it is d then it is directory file

What is the difference between "ls -r" and "ls -R"?

ls -r lists the files in reverse alphabetical order... whereas ls -R lists the files and directories recursively

The difference between a soft link and a hard link?

A symbolic (soft) linked file and the targeted file can be located on the same or different file system while for a hard link they must be located on the same file system.

What are the different commands used to create files?

1. touch - to create empty files (e.g) - touch <filename>
2. vi <filename>
3. cat>filename

List some wild card characters?

? -> Iit matches any single character
* -> It matches zero or more characters
[] -> It matches any single character in given list
. -> It matches any single character except enter key character

What is the output of the follwing command : ls [a-mno-r]* 

list all the files in the current directory starting alphabet
is between a to m  or n or between o to r

How do you count words, lines and characters in a file? 

Wc <filename>

Which command is used to identify the type of the file?

file
"grep" means 
Globally search a regular expression and print it

How do you search for a string inside a given file? 

grep string filename

How do you search for a string inside a  current directory? 

grep string *

How do you search for a string in a directory with the subdirectories recursed?

grep -r string *

Difference between grep, egrep and fgrep.

grep : does not accept more then one expression

egrep : accepts more than one pattern for search. Also accepts patterns from a file.

fgrep : accepts multiple patterns both from command line and file but does not accept regular expressions only strings. It is faster than the other two and should be used when using fixed strings.

What are line patterns?

^ -? start of the line
$ -? End of the line

How to search empty lines in a given file?

Grep “^$” <filename>

Unix Tips

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.