This document provides an overview of common UNIX commands for navigating directories, listing files, editing text, searching for files and strings, compressing files, and more. It describes commands like ls, cd, pwd, vi, grep, find, tar, gzip and man for viewing manual pages. It also explains concepts like pipes, redirection, environment variables and basics of the awk command for text manipulation.
Introduction to command line tools for *NIX (UNIX (like OS X and Solaris/SunOS), BSD, & GNU/Linux) environments. I made this presentation originally for the LUG@UCF when I was an undergrad but still contains valid information. Hope you find it useful.
Introduction to command line tools for *NIX (UNIX (like OS X and Solaris/SunOS), BSD, & GNU/Linux) environments. I made this presentation originally for the LUG@UCF when I was an undergrad but still contains valid information. Hope you find it useful.
we need to have a good amount of basic or in-depth knowledge on Linux Basics. This will help one's job easy in resolving the issues and supporting the projects.
Are you a system admin or database admin? Or working on any other technology which is deployed or implemented on linux/UNIX machines? Then you should be good with Linux basic concepts and commands. We will cover this section very clearly.
Linux Commands mentioned here includes basic as well advanced linux commands which we use on a daily basis. These commands can also help you to crack interview.
Course 102: Lecture 3: Basic Concepts And Commands Ahmed El-Arabawy
This lecture covers the basic file management commands
Check the other Lectures and courses in
http://Linux4EnbeddedSystems.com
or Follow our Facebook Group at
- Facebook: @LinuxforEmbeddedSystems
Lecturer Profile:
- https://www.linkedin.com/in/ahmedelarabawy
Our lab planned a one-week lecture for bioinformatics beginners. I am right now the system administrator of Linux servers, NAS and Vms, so i want to teach the basics of linux system for new Linux users. And i wish to share my slide with you.
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS
This slide is part of the BITS training session: "Introduction to linux for life sciences."
See http://www.bits.vib.be/index.php?option=com_content&view=article&id=17203890%3Abioperl-additional-material&catid=84&Itemid=284
Snmp Opc Server from Transcend Automationguestd1aebad0
SNMP OPC Server will let your automation system both monitor and manage your automation infrastructure. In addition to monitoring your PLCs and Field Devices, you will be able to communicate with all the pieces that make up your automation network, the backbone of your plant.
we need to have a good amount of basic or in-depth knowledge on Linux Basics. This will help one's job easy in resolving the issues and supporting the projects.
Are you a system admin or database admin? Or working on any other technology which is deployed or implemented on linux/UNIX machines? Then you should be good with Linux basic concepts and commands. We will cover this section very clearly.
Linux Commands mentioned here includes basic as well advanced linux commands which we use on a daily basis. These commands can also help you to crack interview.
Course 102: Lecture 3: Basic Concepts And Commands Ahmed El-Arabawy
This lecture covers the basic file management commands
Check the other Lectures and courses in
http://Linux4EnbeddedSystems.com
or Follow our Facebook Group at
- Facebook: @LinuxforEmbeddedSystems
Lecturer Profile:
- https://www.linkedin.com/in/ahmedelarabawy
Our lab planned a one-week lecture for bioinformatics beginners. I am right now the system administrator of Linux servers, NAS and Vms, so i want to teach the basics of linux system for new Linux users. And i wish to share my slide with you.
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS
This slide is part of the BITS training session: "Introduction to linux for life sciences."
See http://www.bits.vib.be/index.php?option=com_content&view=article&id=17203890%3Abioperl-additional-material&catid=84&Itemid=284
Snmp Opc Server from Transcend Automationguestd1aebad0
SNMP OPC Server will let your automation system both monitor and manage your automation infrastructure. In addition to monitoring your PLCs and Field Devices, you will be able to communicate with all the pieces that make up your automation network, the backbone of your plant.
A computer network is defined as the interconnection of two or more computers. It is done to enable the computers to communicate and share available resources.
Components of computer network
Network benefits
Disadvantages of computer network
Classification by their geographical area
Network classification by their component role
Types of servers
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
1.4 modern child centered education - mahatma gandhi-2.pptx
Directories description
1. 1 | P a g e U N I X C o m m a n d s
Directories:
File and directory paths in UNIX use the forward slash "/"
to separate directory names in a path.
examples:
/ "root" directory
/usr directory usr (sub-directory of / "root" directory)
/usr/STRIM100 STRIM100 is a subdirectory of /usr
Moving around the file system:
pwd Show the "present working directory", or current
directory.
cd Change current directory to your HOME directory.
cd /usr/STRIM100 Change current directory to /usr/STRIM100.
cd INIT Change current directory to INIT which is a sub-directory
of the current
directory.
cd .. Change current directory to the parent directory of the
current directory.
cd $STRMWORK Change current directory to the directory defined
by the environment
variable 'STRMWORK'.
cd ~bob Change the current directory to the user bob's home
directory (if you have permission).
Listing directory contents:
2. 2 | P a g e U N I X C o m m a n d s
ls list a directory
ls -l list a directory in long ( detailed ) format
for example:
$ ls -l
drwxr-xr-x 4 cliff user 1024 Jun 18 09:40 WAITRON_EARNINGS
-rw-r--r-- 1 cliff user 767392 Jun 6 14:28 scanlib.tar.gz
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | | | | |
| | | | | owner group size date time name
| | | | number of links to file or directory contents
| | | permissions for world
| | permissions for members of group
| permissions for owner of file: r = read, w = write, x = execute -=no
permission
type of file: - = normal file, d=directory, l = symbolic link, and others...
ls -a List the current directory including hidden files. Hidden files
start
with "."
ls -ld * List all the file and directory names in the current directory
using
long format. Without the "d" option, ls would list the contents
of any sub-directory of the current. With the "d" option, ls
just lists them like regular files.
Changing file permissions and attributes
chmod 755 file Changes the permissions of file to be rwx for the
owner, and rx for
3. 3 | P a g e U N I X C o m m a n d s
the group and the world. (7 = rwx = 111 binary. 5 = r-x = 101
binary)
chgrp user file Makes file belong to the group user.
chown cliff file Makes cliff the owner of file.
chown -R cliff dir Makes cliff the owner of dir and everything in its
directory tree.
You must be the owner of the file/directory or be root before you can
do any of these things.
Moving, renaming, and copying files:
cp file1 file2 copy a file
mv file1 newname move or rename a file
mv file1 ~/AAA/ move file1 into sub-directory AAA in your home
directory.
rm file1 [file2 ...] remove or delete a file
rm -r dir1 [dir2...] recursivly remove a directory and its contents BE
CAREFUL!
mkdir dir1 [dir2...] create directories
mkdir -p dirpath create the directory dirpath, including all implied
directories in the path.
rmdir dir1 [dir2...] remove an empty directory
Viewing and editing files:
cat filename Dump a file to the screen in ascii.
more filename Progressively dump a file to the screen: ENTER = one
line down
SPACEBAR = page down q=quit
4. 4 | P a g e U N I X C o m m a n d s
less filename Like more, but you can use Page-Up too. Not on all
systems.
vi filename Edit a file using the vi editor. All UNIX systems will have
vi in some form.
emacs filename Edit a file using the emacs editor. Not all systems will
have emacs.
head filename Show the first few lines of a file.
head -n filename Show the first n lines of a file.
tail filename Show the last few lines of a file.
tail -n filename Show the last n lines of a file.
Shells
The behavior of the command line interface will differ slightly
depending
on the shell program that is being used.
Depending on the shell used, some extra behaviors can be quite nifty.
You can find out what shell you are using by the command:
echo $SHELL
Of course you can create a file with a list of shell commands and
execute it like
a program to perform a task. This is called a shell script. This is in fact
the
primary purpose of most shells, not the interactive command line
behavior.
5. 5 | P a g e U N I X C o m m a n d s
Environment variables
You can teach your shell to remember things for later using
environment variables.
For example under the bash shell:
export CASROOT=/usr/local/CAS3.0 Defines the variable
CASROOT with the value
/usr/local/CAS3.0.
export LD_LIBRARY_PATH=$CASROOT/Linux/lib Defines the variable
LD_LIBRARY_PATH with
the value of CASROOT with /Linux/lib
appended,
or /usr/local/CAS3.0/Linux/lib
By prefixing $ to the variable name, you can evaluate it in any
command:
cd $CASROOT Changes your present working directory to the value
of CASROOT
echo $CASROOT Prints out the value of CASROOT, or
/usr/local/CAS3.0
printenv CASROOT Does the same thing in bash and some other
shells.
Interactive History
A feature of bash and tcsh (and sometimes others) you can use
the up-arrow keys to access your previous commands, edit
6. 6 | P a g e U N I X C o m m a n d s
them, and re-execute them.
Filename Completion
A feature of bash and tcsh (and possibly others) you can use the
TAB key to complete a partially typed filename. For example if you
have a file called constantine-monks-and-willy-wonka.txt in your
directory and want to edit it you can type 'vi const', hit the TAB key,
and the shell will fill in the rest of the name for you (provided the
completion is unique).
Bash is the way cool shell.
Bash will even complete the name of commands and environment
variables.
And if there are multiple completions, if you hit TAB twice bash will
show
you all the completions. Bash is the default user shell for most Linux
systems.
Redirection:
grep string filename > newfile Redirects the output of the above
grep
command to a file 'newfile'.
grep string filename >> existfile Appends the output of the grep
command
to the end of 'existfile'.
7. 7 | P a g e U N I X C o m m a n d s
The redirection directives, > and >> can be used on the output of most
commands
to direct their output to a file.
Pipes:
The pipe symbol "|" is used to direct the output of one command to the
input
of another.
For example:
ls -l | more This commands takes the output of the long format
directory list command
"ls -l" and pipes it through the more command (also known as a
filter).
In this case a very long list of files can be viewed a page at a
time.
du -sc * | sort -n | tail
The command "du -sc" lists the sizes of all files and directories
in the
current working directory. That is piped through "sort -n"
which orders the
output from smallest to largest size. Finally, that output is
piped through "tail"
which displays only the last few (which just happen to be the
largest) results.
Command Substitution
8. 8 | P a g e U N I X C o m m a n d s
You can use the output of one command as an input to another
command in another way
called command substitution. Command substitution is invoked when
by enclosing the
substituted command in backwards single quotes. For example:
cat `find . -name aaa.txt`
which will cat ( dump to the screen ) all the files named aaa.txt that
exist in the current
directory or in any subdirectory tree.
Searching for strings in files: The grep command
grep string filename prints all the lines in a file that contain the string
Searching for files : The find command
find search_path -name filename
find . -name aaa.txt Finds all the files named aaa.txt in the current
directory or
any subdirectory tree.
find / -name vimrc Find all the files named 'vimrc' anywhere on the
system.
find /usr/local/games -name "*xpilot*"
Find all files whose names contain the string 'xpilot' which
9. 9 | P a g e U N I X C o m m a n d s
exist within the '/usr/local/games' directory tree.
Reading and writing tapes, backups, and archives: The tar command
The tar command stands for "tape archive". It is the "standard" way to
read
and write archives (collections of files and whole directory trees).
Often you will find archives of stuff with names like stuff.tar, or
stuff.tar.gz. This
is stuff in a tar archive, and stuff in a tar archive which has been
compressed using the
gzip compression program respectivly.
Chances are that if someone gives you a tape written on a UNIX system,
it will be in tar format,
and you will use tar (and your tape drive) to read it.
Likewise, if you want to write a tape to give to someone else, you
should probably use
tar as well.
Tar examples:
tar xv Extracts (x) files from the default tape drive while listing (v =
verbose)
the file names to the screen.
tar tv Lists the files from the default tape device without extracting
them.
tar cv file1 file2
Write files 'file1' and 'file2' to the default tape device.
10. 10 | P a g e U N I X C o m m a n d s
tar cvf archive.tar file1 [file2...]
Create a tar archive as a file "archive.tar" containing file1,
file2...etc.
tar xvf archive.tar extract from the archive file
tar cvfz archive.tar.gz dname
Create a gzip compressed tar archive containing everything in
the directory
'dname'. This does not work with all versions of tar.
tar xvfz archive.tar.gz
Extract a gzip compressed tar archive. Does not work with all
versions of tar.
tar cvfI archive.tar.bz2 dname
Create a bz2 compressed tar archive. Does not work with all
versions of tar
File compression: compress, gzip, and bzip2
The standard UNIX compression commands are compress and
uncompress. Compressed files have
a suffix .Z added to their name. For example:
compress part.igs Creates a compressed file part.igs.Z
uncompress part.igs Uncompresseis part.igs from the compressed file
part.igs.Z.
Note the .Z is not required.
Another common compression utility is gzip (and gunzip). These are the
GNU compress and
uncompress utilities. gzip usually gives better compression than
standard compress,
11. 11 | P a g e U N I X C o m m a n d s
but may not be installed on all systems. The suffix for gzipped files is
.gz
gzip part.igs Creates a compressed file part.igs.gz
gunzip part.igs Extracts the original file from part.igs.gz
The bzip2 utility has (in general) even better compression than gzip, but
at the cost of longer
times to compress and uncompress the files. It is not as common a
utility as gzip, but is
becoming more generally available.
bzip2 part.igs Create a compressed Iges file part.igs.bz2
bunzip2 part.igs.bz2 Uncompress the compressed iges file.
Looking for help: The man and apropos commands
Most of the commands have a manual page which give sometimes
useful, often more or less
detailed, sometimes cryptic and unfathomable discriptions of their
usage. Some say they
are called man pages because they are only for real men.
Example:
man ls Shows the manual page for the ls command
You can search through the man pages using apropos
Example:
12. 12 | P a g e U N I X C o m m a n d s
apropos build Shows a list of all the man pages whose discriptions
contain the word "build"
Do a man apropos for detailed help on apropos.
Basics of the vi editor
Opening a file
vi filename
Creating text
Edit modes: These keys enter editing modes and type in the text
of your document.
i Insert before current cursor position
I Insert at beginning of current line
a Insert (append) after current cursor position
A Append to end of line
r Replace 1 character
R Replace mode
<ESC> Terminate insertion or overwrite mode
Deletion of text
x Delete single character
dd Delete current line and put in buffer
ndd Delete n lines (n is a number) and put them in buffer
J Attaches the next line to the end of the current line (deletes
carriage return).
Oops
13. 13 | P a g e U N I X C o m m a n d s
u Undo last command
cut and paste
yy Yank current line into buffer
nyy Yank n lines into buffer
p Put the contents of the buffer after the current line
P Put the contents of the buffer before the current line
cursor positioning
^d Page down
^u Page up
:n Position cursor at line n
:$ Position cursor at end of file
^g Display current line number
h,j,k,l Left,Down,Up, and Right respectivly. Your arrow keys should also
work if
if your keyboard mappings are anywhere near sane.
string substitution
:n1,n2:s/string1/string2/[g] Substitute string2 for string1 on lines
n1 to n2. If g is included (meaning global),
all instances of string1 on each line
are substituted. If g is not included,
only the first instance per matching line is
substituted.
^ matches start of line
. matches any single character
$ matches end of line
These and other "special characters" (like the forward slash) can be
"escaped" with
14. 14 | P a g e U N I X C o m m a n d s
i.e to match the string "/usr/STRIM100/SOFT" say
"/usr/STRIM100/SOFT"
Examples:
:1,$:s/dog/cat/g Substitute 'cat' for 'dog', every instance
for the entire file - lines 1 to $ (end of file)
:23,25:/frog/bird/ Substitute 'bird' for 'frog' on lines
23 through 25. Only the first instance
on each line is substituted.
Saving and quitting and other "ex" commands
These commands are all prefixed by pressing colon (:) and then entered
in the lower
left corner of the window. They are called "ex" commands because they
are commands
of the ex text editor - the precursor line editor to the screen editor
vi. You cannot enter an "ex" command when you are in an edit mode
(typing text onto the screen)
Press <ESC> to exit from an editing mode.
:w Write the current file.
:w new.file Write the file to the name 'new.file'.
:w! existing.file Overwrite an existing file with the file currently being
edited.
:wq Write the file and quit.
:q Quit.
:q! Quit with no changes.
:e filename Open the file 'filename' for editing.
15. 15 | P a g e U N I X C o m m a n d s
:set number Turns on line numbering
:set nonumber Turns off line numbering
awk COMMAND:
awk command is used to manipulate the text.This command checks each line of a file, looking for
patterns that match those given on the command line.
SYNTAX:
The Syntax is
awk '{pattern + action}' {filenames}
OPTIONS:
-W version Display version information and exit.
-F Print help message and exit.
EXAMPLE:
Lets create a file file1.txt and let it have the following data:
Data in
file1.txt
141516
151511
5566
5251
1. To print the second column data in file1.txt
awk '{print $2}' file1.txt
This command will manipulate and print second column of text file (file1.txt). The output will look
like
15
15
16. 16 | P a g e U N I X C o m m a n d s
56
25
2. To multiply the column-1 and column-2 and redirect the output to file2.txt:
awk '{print $1,$2,$1*$2}' file1.txt > file2.txt
Command Explanation:
$1 :Prints 1st column
$2 :Prints 2ndcolumn
$1*$2 :Prints Result of $1 x $2
file1.txt : input file
> : redirection symbol
file2.txt : output file
The above command will redirect the output to file2.txt and it will look like,
14 15 210
15 15 225
5 56 280
5 25 125
Contents
cat --- for creating and displaying short files
chmod --- change permissions
cd --- change directory
cp --- for copying files
date --- display date
echo --- echo argument
ftp --- connect to a remote machine to download or upload files
grep --- search file
head --- display first part of file
ls --- see what files you have
lpr --- standard print command (see also print )
more --- use to read files
17. 17 | P a g e U N I X C o m m a n d s
mkdir --- create directory
mv --- for moving and renaming files
ncftp --- especially good for downloading files via anonymous ftp.
print --- custom print command (see also lpr )
pwd --- find out what directory you are in
rm --- remove a file
rmdir --- remove directory
rsh --- remote shell
setenv --- set an environment variable
sort --- sort file
tail --- display last part of file
tar --- create an archive, add or extract files
telnet --- log in to another machine
wc --- count characters, words, lines
cat
This is one of the most flexible Unix commands. We can use to create, view and
concatenate files. For our first example we create a three-item English-Spanish
dictionary in a file called "dict."
% cat >dict
red rojo
green verde
blue azul
<control-D>
%
<control-D> stands for "hold the control key down, then tap 'd'". The symbol > tells
the computer that what is typed is to be put into the file dict. To view a file we
use cat in a different way:
% cat dict
red rojo
green verde
blue azul
%
If we wish to add text to an existing file we do this:
% cat >>dict
white blanco
black negro
<control-D>
%
18. 18 | P a g e U N I X C o m m a n d s
Now suppose that we have another file tmp that looks like this:
% cat tmp
cat gato
dog perro
%
Then we can join dict and tmp like this:
% cat dict tmp >dict2
We could check the number of lines in the new file like this:
% wc -l dict2
8
The command wc counts things --- the number of characters, words, and line in a file.
chmod
This command is used to change the permissions of a file or directory. For example to
make a file essay.001 readable by everyone, we do this:
% chmod a+r essay.001
To make a file, e.g., a shell script mycommand executable, we do this
% chmod +x mycommand
Now we can run mycommand as a command.
To check the permissions of a file, use ls -l . For more information on chmod, use man
chmod.
cd
Use cd to change directory. Use pwd to see what directory you are in.
% cd english
% pwd
% /u/ma/jeremy/english
% ls
novel poems
% cd novel
% pwd
% /u/ma/jeremy/english/novel
% ls
19. 19 | P a g e U N I X C o m m a n d s
ch1 ch2 ch3 journal scrapbook
% cd ..
% pwd
% /u/ma/jeremy/english
% cd poems
% cd
% /u/ma/jeremy
Jeremy began in his home directory, then went to his english subdirectory. He listed
this directory using ls , found that it contained two entries, both of which happen to be
diretories. He cd'd to the diretory novel, and found that he had gotten only as far as
chapter 3 in his writing. Then he used cd .. to jump back one level. If had wanted to
jump back one level, then go to poems he could have said cd ../poems. Finally he
used cd with no argument to jump back to his home directory.
cp
Use cp to copy files or directories.
% cp foo foo.2
This makes a copy of the file foo.
% cp ~/poems/jabber .
This copies the file jabber in the directory poems to the current directory. The symbol
"." stands for the current directory. The symbol "~" stands for the home directory.
date
Use this command to check the date and time.
% date
Fri Jan 6 08:52:42 MST 1995
echo
The echo command echoes its arguments. Here are some examples:
% echo this
this
% echo $EDITOR
/usr/local/bin/emacs
% echo $PRINTER
b129lab1
20. 20 | P a g e U N I X C o m m a n d s
Things like PRINTER are so-called environment variables. This one stores the name of
the default printer --- the one that print jobs will go to unless you take some action to
change things. The dollar sign before an environment variable is needed to get the
value in the variable. Try the following to verify this:
% echo PRINTER
PRINTER
ftp
Use ftp to connect to a remote machine, then upload or download files. See
also: ncftp
Example 1: We'll connect to the machine fubar.net, then change director to mystuff,
then download the file homework11:
% ftp solitude
Connected to fubar.net.
220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT
1994) ready.
Name (solitude:carlson): jeremy
331 Password required for jeremy.
Password:
230 User jeremy logged in.
ftp> cd mystuff
250 CWD command successful.
ftp> get homework11
ftp> quit
Example 2: We'll connect to the machine fubar.net, then change director to mystuff,
then upload the file collected-letters:
% ftp solitude
Connected to fubar.net.
220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT
1994) ready.
Name (solitude:carlson): jeremy
331 Password required for jeremy.
Password:
230 User jeremy logged in.
ftp> cd mystuff
250 CWD command successful.
ftp> put collected-letters
ftp> quit
The ftp program sends files in ascii (text) format unless you specify binary mode:
ftp> binary
ftp> put foo
21. 21 | P a g e U N I X C o m m a n d s
ftp> ascii
ftp> get bar
The file foo was transferred in binary mode, the file bar was transferred in ascii mode.
grep
Use this command to search for information in a file or files. For example, suppose
that we have a file dict whose contents are
red rojo
green verde
blue azul
white blanco
black negro
Then we can look up items in our file like this;
% grep red dict
red rojo
% grep blanco dict
white blanco
% grep brown dict
%
Notice that no output was returned by grep brown. This is because "brown" is not in
our dictionary file.
Grep can also be combined with other commands. For example, if one had a file of
phone numbers named "ph", one entry per line, then the following command would
give an alphabetical list of all persons whose name contains the string "Fred".
% grep Fred ph | sort
Alpha, Fred: 333-6565
Beta, Freddie: 656-0099
Frederickson, Molly: 444-0981
Gamma, Fred-George: 111-7676
Zeta, Frederick: 431-0987
The symbol "|" is called "pipe." It pipes the output of the grep command into the input
of the sort command.
For more information on grep, consult
% man grep
head
Use this command to look at the head of a file. For example,
22. 22 | P a g e U N I X C o m m a n d s
% head essay.001
displays the first 10 lines of the file essay.001 To see a specific number of lines, do
this:
% head -n 20 essay.001
This displays the first 20 lines of the file.
ls
Use ls to see what files you have. Your files are kept in something called a directory.
% ls
foo letter2
foobar letter3
letter1 maple-assignment1
%
Note that you have six files. There are some useful variants of the ls command:
% ls l*
letter1 letter2 letter3
%
Note what happened: all the files whose name begins with "l" are listed. The asterisk
(*) is the " wildcard" character. It matches any string.
lpr
This is the standard Unix command for printing a file. It stands for the ancient "line
printer." See
% man lpr
for information on how it works. See print for information on our local intelligent print
command.
mkdir
Use this command to create a directory.
% mkdir essays
23. 23 | P a g e U N I X C o m m a n d s
To get "into" this directory, do
% cd essays
To see what files are in essays, do this:
% ls
There shouldn't be any files there yet, since you just made it. To create files,
see cat or emacs.
more
More is a command used to read text files. For example, we could do this:
% more poems
The effect of this to let you read the file "poems ". It probably will not fit in one
screen, so you need to know how to "turn pages". Here are the basic commands:
q --- quit more
spacebar --- read next page
return key --- read next line
b --- go back one page
For still more information, use the command man more.
mv
Use this command to change the name of file and directories.
% mv foo foobar
The file that was named foo is now named foobar
ncftp
Use ncftp for anonymous ftp --- that means you don't have to have a password.
% ncftp ftp.fubar.net
Connected to ftp.fubar.net
> get jokes.txt
24. 24 | P a g e U N I X C o m m a n d s
The file jokes.txt is downloaded from the machine ftp.fubar.net.
print
This is a moderately intelligent print command.
% print foo
% print notes.ps
% print manuscript.dvi
In each case print does the right thing, regardless of whether the file is a text file
(like foo ), a postcript file (like notes.ps, or a dvi file (like manuscript.dvi. In these
examples the file is printed on the default printer. To see what this is, do
% print
and read the message displayed. To print on a specific printer, do this:
% print foo jwb321
% print notes.ps jwb321
% print manuscript.dvi jwb321
To change the default printer, do this:
% setenv PRINTER jwb321
pwd
Use this command to find out what directory you are working in.
% pwd
/u/ma/jeremy
% cd homework
% pwd
/u/ma/jeremy/homework
% ls
assign-1 assign-2 assign-3
% cd
% pwd
/u/ma/jeremy
%
Jeremy began by working in his "home" directory. Then he cd 'd into his homework
subdirectory. Cd means " change directory". He used pwd to check to make sure he
was in the right place, then used ls to see if all his homework files were there. (They
were). Then he cd'd back to his home directory.
rm
25. 25 | P a g e U N I X C o m m a n d s
Use rm to remove files from your directory.
% rm foo
remove foo? y
% rm letter*
remove letter1? y
remove letter2? y
remove letter3? n
%
The first command removed a single file. The second command was intended to
remove all files beginning with the string "letter." However, our user (Jeremy?)
decided not to remove letter3.
rmdir
Use this command to remove a directory. For example, to remove a directory called
"essays", do this:
% rmdir essays
A directory must be empty before it can be removed. To empty a directory, use rm.
rsh
Use this command if you want to work on a computer different from the one you are
currently working on. One reason to do this is that the remote machine might be
faster. For example, the command
% rsh solitude
connects you to the machine solitude. This is one of our public workstations and is
fairly fast.
See also: telnet
setenv
% echo $PRINTER
labprinter
% setenv PRINTER myprinter
% echo $PRINTER
26. 26 | P a g e U N I X C o m m a n d s
myprinter
sort
Use this commmand to sort a file. For example, suppose we have a file dict with
contents
red rojo
green verde
blue azul
white blanco
black negro
Then we can do this:
% sort dict
black negro
blue azul
green verde
red rojo
white blanco
Here the output of sort went to the screen. To store the output in file we do this:
% sort dict >dict.sorted
You can check the contents of the file dict.sorted using cat , more , or emacs .
tail
Use this command to look at the tail of a file. For example,
% tail essay.001
displays the last 10 lines of the file essay.001 To see a specific number of lines, do
this:
% tail -n 20 essay.001
This displays the last 20 lines of the file.
tar
Use create compressed archives of directories and files, and also to extract directories
and files from an archive. Example:
% tar -tvzf foo.tar.gz
displays the file names in the compressed archive foo.tar.gz while
% tar -xvzf foo.tar.gz
27. 27 | P a g e U N I X C o m m a n d s
extracts the files.
telnet
Use this command to log in to another machine from the machine you are currently
working on. For example, to log in to the machine "solitude", do this:
% telnet solitude
See also: rsh.
wc
Use this command to count the number of characters, words, and lines in a file.
Suppose, for example, that we have a file dict with contents
red rojo
green verde
blue azul
white blanco
black negro
Then we can do this
% wc dict
5 10 56 tmp
This shows that dict has 5 lines, 10 words, and 56 characters.
The word count command has several options, as illustrated below:
% wc -l dict
5 tmp
% wc -w dict
10 tmp
% wc -c dict
56 tmp