Basic commands for Linux with Examples
Making or Removing a Directory (terminal mode)
Thank you
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
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.
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.
This will tell you how much disk space you have left on your hard drive as well as the floppy.
Linux Rename File Command
How do I rename a file called resumezzz.pdf to resume.pdf
using Linux bash command prompt?
You need to use the mv command. It is used to rename and move files and
directories. The general
syntax is as follows:
mv old-file-name new-file-name
mv [options] old-file-name
new-file-name
mv file1 file2
In this example, the following command would rename a file called
resumezzz.pdf to resume.pdf. Open a command-line terminal (select Applications
> Accessories > Terminal), and then type:
mv resumezzz.pdf resume.pdf
If resumezzz.pdf is located in /home/vivek/docs/files directory, type:
cd /home/vivek/docs/files
mv resumezzz.pdf resume.pdf
OR
mv /home/vivek/docs/files/resumezzz.pdf /home/vivek/docs/files/resume.pdf
Use the ls command to view files:
ls -l file1
ls -l file1 file2
ls -l /home/vivek/docs/files/*.pdf
ls -l *.pdf
Linux rename a file syntax
In short, to rename a file:
mv file1 file2
You can get verbose output i.e. mv command can explain what is being done
using the following syntax:
mv -v file1 file2
Sample outputs:
`file1' -> `file2'
To make mv interactive pass the -i option. This option will prompt before
overwriting file:
mv -i file1 file2
Sample outputs:
mv: overwrite `file2'? y
Detailed information about mv command
You can also view the manual page on mv using the following command:
man mv
OR
info mv
Thank you
No comments:
Post a Comment