Unix FAQ

New to Unix and need some basic commands ?
In this FAQ Basic commands What no feedback ?  
Getting Help - 'man' manual page sections finding a command
Looking for the error: windex: No such file or directory ?


Unix FAQ Menu
Contents
Basic commands
Cron
Creating CDs
Device Files
DHCP server (Solaris)
Filesystem explained
Fsck
grub/lilo vanished!
Linux applications?
Linux databases?
Linux distributions
Serial Console
Solaris devices
Solaris disks - Intro
Solaris disks - Adding
Solaris x86 install
SQL/Shell script
Syslog/Monitoring
Time Synchronisation.
Virtual Memory
Web Multi-Language
Web Server Errors
Humour
Unix a Prank



 

Good This page has received an average rating of 75% from 9 readers

Question:

I'm new to Linux and need some basic commands. I am lost how to list a directory, delete or rename a files, and search for strings and files. Apparently I've got a Shell. What is a shell ?

Sorry this is really basic but I don't know where to start..
Thanks,
Maria.

Answer:

Well the short answer to your question is that ls lists a directory, rm deletes and mv renames files. grep searches for strings in files, and find searches for files. A Shell is Unix jargon for a command line interpreter - simply a program you enter commands into and it does something useful with them, well hopefully.

Might by worth mentioning that there are two main flavours of shell - "Bourne" and "C" shells, at some point you may need to find out which you have, but at the moment its not that important to you.

Below are some basic Unix commands you'll find useful, these are intended for both beginners & intermediate users, in alphabetical order;

command notes
cat concatenate files
cd change directory
chmod change permissions
cp copy file(s)
df show free space on disk
exit exit the shell
file long description of file - type
find find /search for a file.
grep search for strings in files
head list the top/head of a file
ls list directory
man show a manual page
more list a file page-by-page
   
command notes
mkdir Make/create directory
mv move or rename files
ps what programs are running
pwd print working directory
rm remove a file
rmdir Remove a directory
sort sort a file alphabetically
tail list the end of a file (see -f)
touch create an empty file
vi text editor
wc count lines/words in a file
which which program will be run
who who is logged on
   

What no feedback ?

One quirk of many Unix commands that newcomers find disturbing it they don't report anything if the command succeeds. This is probably most perturbing with command like rm and rmdir which delete files and directories;

shell% touch somefile
shell% ls -l somefile
-rw-------   1 andrew   mercury        0 Jun 11 16:35 somefile
shell% rm somefile shell%
Notice how the commands touch and rm reported nothing - they worked ok However, If you try to delete the same file again...
shell% rm somefile
somefile: No such file or directory
shell% 

The behaviour seems a little odd if you're used to verbose operating systems like Windows or VMS, but this is all part of the Unix philosophy - why report anything when's there's nothing to say?
You could liken it to the difference between men and women    [ You could, I couldn't. I'm married......]

Getting Help; The manual and the 'man' command.

There's no help command for Unix, well if there is your site has made some special effort to provide it. The nearest thing is the man command - manual page. Say we wanted more information about the 'mkdir' command.

shell% man mkdir
User Commands mkdir(1) NAME mkdir - make directories SYNOPSIS mkdir [ -m mode ] [ -p ] dir ... DESCRIPTION The mkdir command creates the named directories in mode 777 (possibly altered by the file mode creation mask umask(1)). Standard entries in a directory (for instance, the files ".", for the directory itself, and "..", for its parent) are made automatically. mkdir cannot create these entries by name. Creation of a directory requires write permission in the parent directory..........

The synopsis shows how to use the command and any options it may have. The square brackets '[]' indicate that that parameter is optional. In this case mkdir has the options -m and -p. -m requires a mode argument. The parameter dir (name of directory) is compulsory. The '...' denotes that there can be more 'dir' arguments - you can create multiple directories with one command.

Manual page sections

Note the top line of the above manual page - mkdir(1).

You'll likely witness this a lot as you learn more about Unix. The number in brackets is the section number in the manual. The entry above came from section 1 - User Commands.

You may come across references like "see lpc(8) for more information". This simply is referring you to the entry for lpc (line printer control) in section 8 of the manual.

You can specify the section number to the man command, on Solaris use 'man -s 2 mkdir', on Linux and some other systems you should use 'man 2 mkdir'.

shell% man -s 2 mkdir 
System Calls                                             mkdir(2)


NAME
     mkdir - make a directory


SYNOPSIS
     #include <sys/types.h>
     #include <sys/stat.h>

     int mkdir(const char *path, mode_t mode);

DESCRIPTION 
   .............

Now you can see there is another manual page entry for mkdir, this time in section #2 - System Calls. This section is primarily aimed at programmers, we shown it here simply to demonstrate that the same name can exist in different sections. If you use the man command and see something completely unexpected check the man page section at top of the page.

Keyword searches / Finding a command

Before finishing up with the 'man' command one last useful feature is worth a mention - keyword searches. By using the '-k' option on the 'man' command you can find all the commands with that word in their description field. This can be quite useful when you don't know the name of a command;

shell% man -k mkdir

sun (bash) % man -k mkdir
mkdir mkdir (1) - make directories
mkdir mkdir (2) - make a directory
mkdirp mkdirp (3g) - create, remove directories in a path
nis_mkdir nis_server (3n) - miscellaneous NIS+ functions
nismkdir nismkdir (1) - create NIS+ directories
rmdirp mkdirp (3g) - create, remove directories in a path

If you're only looking for commands you can ignore any pages that are not in Section 1 - User Commands. Later on you might also be interested in section 8 - Maintenance Commands
Notes: Some older systems support keyword searches via the command apropos
  windex. If you get an error like /usr/man/windex: No such file or directory
this means that the manual page index hasn't been created - have a word with your system admins and ask them to run the command catman -w

Tips:

To search for a string (e.g "xyx") in all the files in the current directory, try;
    % find . -type f -exec grep xyz '{}' /dev/null \;
This causes find to run "grep xyz <file>" on every plain file ("-type f")


Feedback

I hope you found this FAQ to be of some use. It would be most helpful if you could rate it below. All fields are optional...
Please do not use this form to seek free technical assistance - Try AllExperts...

Excellent Your Email:
Good Comments or Suggestions
Useful
Slightly useful
Not useful
        



Home Thai Guide   Great Circle Calculator WorldClock AMS Services Contact us