0% found this document useful (0 votes)
3 views

linux basics

This document provides a comprehensive guide to basic Linux and UNIX commands, including file manipulation, directory management, and software installation. It covers commands such as 'cd', 'cp', 'mv', 'mkdir', and 'rm', as well as how to use tar, gzip, and bzip2 for file compression. Additionally, it explains the use of terminal and graphical user interface modes, and the importance of mounting and unmounting drives, particularly floppy disks.

Uploaded by

akdeniz.erdem
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

linux basics

This document provides a comprehensive guide to basic Linux and UNIX commands, including file manipulation, directory management, and software installation. It covers commands such as 'cd', 'cp', 'mv', 'mkdir', and 'rm', as well as how to use tar, gzip, and bzip2 for file compression. Additionally, it explains the use of terminal and graphical user interface modes, and the importance of mounting and unmounting drives, particularly floppy disks.

Uploaded by

akdeniz.erdem
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Getting Started

Here are some basic commands to get you started in the wonderful world of Linux and other
UNIX variants. Near the bottom are commands dealing with tar/gzip/bzip2, compiling, and
Linux RPM management. All UNIX and Linux commands are case sensitive.

cd
Change directory. This is the command you use to change into different directories. An
example would be "cd /mnt" (minus the quotes, always minus the quotes) now you will
be the /mnt dir.
mount
Mounts a filesystem. ex, "mount /dev/hda4 /mnt" mounts hard drive partition 4 in
your /mnt directory.
cp
Copies files. eg, "cp SomeFile /home/momo/" copies a SomeFile into user momo's
home directory.
mv
Move. Does the same as cp except moves the file instead of copying it. You also use
the mv command to rename files/directories ex, "mv file1 SomeNewFilename"
renames file1 to SomeNewFilename.
mkdir
Make Directory. ex, "mkdir /home/momo/new" creates a directory named new in
momo's home directory. If you are currently in the directory you want to make the the
new directory in you can just do "mkdir new" to make a directory named "new".
rm
Removes files and directories. ex, "rm file1". To use rm without a hassle you may want
to use "rm -rf". This way you won't be prompted to confirm the removal of the file. You
can not use rm to remove directories which are not empty unless you use an option
telling rm to do otherwise, the -rf option works well for this. Use "rm -rf" carefully ;-).
rmdir
Removes empty directories. ex, "rmdir new".
man
displays the man page for a paticular application or command. ex, "man rm". Man is
your friend, please use it :-) .

Using tar, gzip, and bzip2


untar/gzipping a file
The following will decompress .tar.gz and .tgz files. cd into the dir with the file/s then
type "tar zxvf yourfile.tar.gz" or "tar zxvf yourfile.tgz".
un-tar a .tar
cd into the dir with the file/s then type "tar xvf yourfile.tar".
un-gzip a file
Type "gzip -d filename.gz".
un-bzip2 a file
Type "bzip2 -d filename.bz2".
tar plus gzip a dir/multiple files
cd into the dir of the files you want to tar(warning, this will put ALL files of the current
dir you're in into a tar file), type "tar cvf newTarFile.tar * ". Now to gzip the file, type
"gzip -9 newTarFile.tar".

Compiling and Installing Software


tar.gz or .tgz
untar/gzip the file ("tar zxvf file.tar.gz"). cd into the dir. Most source packages will
compile by doing "./configure" then "make" then su to root (type "su" press enter then
enter in your root password then press enter) and do "make install". I always like to do
"make install > /root/program-version" to keep better track of everything. You should
always read the INSTALL file first, but the above instructions usually work fine. If you
happen to be compiling and installing libs, be sure to type (as root) "ldconfig" after
installing them.
src.rpm
You must be root and in the same dir as the src.rpm. Type "rpm --rebuild --target i586"
(if you have a intel p2 or higher, you can do i686, if you have a 486 or lower do i486 or
i386). Now watch for where the actual rpm was placed (look at last few lines on the
screen or scroll up a tiny bit). cd into the dir with the new rpm or cp it to where you are
at ("cp /path/to/rpm ."). Now do "rpm -Uvh file.rpm".
Note for slackware users
You can compile source rpms using the above instructions, but instead of installing the
rpm, run "rpm2tgz file.rpm" (comes standard with slackware) and install using
"installpkg file.tgz".
Installing a regular RPM
cd into the dir that the rpm you want to install is in. su to root (type "su" press
enter, enter in your root password, press enter). Type "rpm -Uvh filename.rpm"
and press enter, boom done ;-).
Command Example Description
cat Sends file contents to standard output. This is a way to
list the contents of short files to the screen. It works
well with piping.
cat .bashrc Sends the contents of the ".bashrc" file to the screen.
cd Change directory
cd /home Change the current working directory to /home. The '/'
indicates relative to root, and no matter what directory
you are in when you execute this command, the
directory will be changed to "/home".
cd httpd Change the current working directory to httpd, relative
to the current location which is "/home". The full path
of the new working directory is "/home/httpd".
cd .. Move to the parent directory of the current directory.
This command will make the current working
directory "/home.
cd ~ Move to the user's home directory which is
"/home/username". The '~' indicates the users home
directory.
cp Copy files
cp myfile yourfile Copy the files "myfile" to the file "yourfile" in the
current working directory. This command will create
the file "yourfile" if it doesn't exist. It will normally
overwrite it without warning if it exists.
cp -i myfile yourfile With the "-i" option, if the file "yourfile" exists, you
will be prompted before it is overwritten.
cp -i /data/myfile . Copy the file "/data/myfile" to the current working
directory and name it "myfile". Prompt before
overwriting the file.
cp -dpr srcdir destdir Copy all files from the directory "srcdir" to the
directory "destdir" preserving links (-p option), file
attributes (-p option), and copy recursively (-r option).
With these options, a directory and all it contents can
be copied to another directory.
dd Disk duplicate. The man page says this command is to
dd if=/dev/hdb1 "Convert and copy a file", but although used by more
of=/backup/ advanced users, it can be a very handy command. The
"if" means input file, "of" means output file.
df Show the amount of disk space used on each mounted
filesystem.
less Similar to the more command, but the user can page up
less textfile and down through the file. The example displays the
contents of textfile.
ln Creates a symbolic link to a file.
ln -s test symlink Creates a symbolic link named symlink that points to
the file test Typing "ls -i test symlink" will show the
two files are different with different inodes. Typing "ls
-l test symlink" will show that symlink points to the
file test.
locate A fast database driven file locator.
slocate -u This command builds the slocate database. It will take
several minutes to complete this command. This
command must be used before searching for files,
however cron runs this command periodically on most
systems.
locate whereis Lists all files whose names contain the string
"whereis".
logout Logs the current user off the system.
ls List files
ls List files in the current working directory except those
starting with . and only show the file name.
ls -al List all files in the current working directory in long
listing format showing permissions, ownership, size,
and time and date stamp
more Allows file contents or piped output to be sent to the
screen one page at a time.
more /etc/profile Lists the contents of the "/etc/profile" file to the screen
one page at a time.
ls -al |more Performs a directory listing of all files and pipes the
output of the listing through more. If the directory
listing is longer than a page, it will be listed one page
at a time.
mv Move or rename files
mv -i myfile yourfile Move the file from "myfile" to "yourfile". This
effectively changes the name of "myfile" to "yourfile".
mv -i /data/myfile . Move the file from "myfile" from the directory "/data"
to the current working directory.
pwd Show the name of the current working directory
more /etc/profile Lists the contents of the "/etc/profile" file to the screen
one page at a time.
shutdown Shuts the system down.
shutdown -h now Shuts the system down to halt immediately.
shutdown -r now Shuts the system down immediately and the system
reboots.
whereis Show where the binary, source and manual page files
are for a command
whereis ls Locates binaries and manual pages for the ls command
Modes of Operation
The linux operating system used for the PARTICLE DAQ
system can be used either in a terminal mode where you type
commands or in a Windows Explorer style graphical user
interface (GUI).

The Explorer-like GUI can be used for file manipulation


functions (e.g., copying a file to a floppy) or deleting or moving
files on the disk. It cannot be used to run the PARTICLE
DAQ itself.

To begin using the Explorer-like GUI, double click on the icons


on the Desktop. For the most part, Explorer mode will be
familiar from Windows or MAC OS, so with a few exceptions,
this information will not focus on this. Where something is
much more easily done from Explorer mode, it will be
highlighted here.

To begin working in the terminal mode, you will need to open a


terminal. This can be accomplished by clicking on the
terminal icon in the bottom icon bar, by using the main menu
(footprint icon in lower left of bottom icon bar) System Tools -
> New Terminal.
The Manual (terminal mode)
man This command brings up the online Unix
manual. Use it on each of the commands
below.

For Example:
man pwd You will see the manual for the pwd
command.

Accessing files in Folders (Directories) in terminal mode


pwd Shows what directory (folder) you are in.
In Linux, your home directory is
/home/particle

  Let's suppose you have several data files (data1,


data2 ... etc.) in a directory called muondata.
  Then suppose the directory muondata is an entry in
your main home directory, /home/particle .
  If you are in your home directory (where terminals
start) and type pwd, you will see /home/particle.
  If you were in the muondata directory, pwd would give
you /home/particle/muondata instead
  The last slash after a directory name is optional.

As you can see, each slash (/) indicates another sub-directory.


cd Changes directories.

Examples of relative movement among directories:


cd muondata Moves down from your current directory
into the muondata sub-directory

cd .. Moves up one directory (yes, include the


two little dots)

You can also move directly into directories


cd /home/particle/muondata
Moves from ANY directory into the
muondata
sub-directory of your home directory.

cd ~ Takes you back to your home directory


(/home/particle)

Making or Removing a Directory (terminal mode)

mkdir dirName Creates a directory with name dirName.

For Example:
mkdir temp Creates the directory temp.

rmdir dirName Removes a directory dirName.

For Example:
rmdir temp Removes the directory temp.

Looking at or Finding your Files (terminal mode)


ls Lists files.
If you add -al after ls it will give more details for each file.
Such as, size, permissions, owners, dates etc.

ls al You'll see a huge list of files that you can't


see with the 'ls' command alone and lots
of details.

If you see such a long list of files that they scroll off the
terminal screen, one way to solve the problem is to use:

ls -al |more Shows one screen of file names at a time.

less data1 Dumps the contents of the data1 file to


your screen with a pause at each line so
you don't miss any contents as they scroll.
You may move through the file using
page up, page down, home and end keys.
When done with less you use the q key to
get back to the main terminal.

whereis data1 Shows you the location of the data1 file.

Altering your Files

rm data1 Deletes the file data1 in the current


directory.

rm -i muon* Removes all of your muon data files


(careful!! rm * will remove ALL your
files)
The "-i" makes the computer prompt
before removing each file. If you really
want to work without a net, omit the "-i".
cp data1 newdata/ will copy the file data1 to the directory
newdata (assuming it has already been created)

mv data1 newdata/ moves the file data1 to the folder newdata


and deletes the old one.

Using the Floppy Disk Drive in Linux


The simplest way to access the floppy drive under Linux is to
use the Explorer-like interface. However, there is a very
important detail! To access the files on the disk, you have to
mount the floppy disk, which means that the operating system
will scan the disk so that it can recognize the files on it.
Although your computer will be perfectly happy to allow you
to remove the disk by pushing the eject key on the laptop
floppy drive, this may result in unexpected actions unless you
unmount the disk. For example, your files may be only partly
there or not there at all! (This is no different then under
Windows or DOS; its just that those operating systems hide
that detail from you a little better. This is why, for example,
you must eject floppy disks from the disk properties menu in
Windows.)

In the Explorer interface, to mount the floppy, you just double


click on the desktop icon. This will bring up a window with the
contents of the floppy, and you may drag and drop files there,
or take any other actions you would with normal files. (Note:
unlike in Windows and MacOS, when you drag a file from
your home area to the floppy, it moves the file instead of
making a copy.)

To remove the disk, you must first right-click on the desktop


icon, and select Unmount volume or Eject (either does the
same thing). When this is complete (and it may take a long
time since it may have to complete writing files to the floppy!),
you may push the eject button on the floppy to remove it.

Things are more complicated by possible in the terminal mode:

mount Mounts a drive to the operating system.


Linux does not 'see' the floppy drive until
you tell it to.

For Example:
mount /mnt/floppy Allows you to use the floppy drive which
has directory name /mnt/floppy

cp aFile /mnt/floppy/ Copies the file aFile to the floppy


disk.

ls /mnt/qfloppy/ Allows you to see what files are on


your floppy.

You may run into problems moving large files onto a 1.44MB
floppy disk. One option to fit larger files is to create a zip
archive containing the file onto the floppy. For Example:
zip /mnt/floppy/myFile.zip muon.myDataRun
Moves the file muon.myDataRun into a
zip file on the floppy named myFile.zip

After you are done and before you eject it (this is very, very
important), you must unmount the floppy.

umount /mnt/qfloppy Allows you to remove the floppy


disk
  Make sure you wait for the command prompt to
reappear (this might take a few seconds) before ejecting
the floppy.
  If you eject the floppy before you unmount the floppy,
it may corrupt the data on the floppy and cause the
system to be confused if you try to use the floppy again.
  If you make a mistake like this, it's probably best to
reboot. Sorry.

df Shows the disk usage. This will tell you


how much disk space you have left on
your hard drive as well as the floppy.

You might also like