UNIX Basic Commands
UNIX Basic Commands
UNIX Basic Commands
echo
Syntax:
echo [OPTION]... [STRING]...
Example:
Good Morning
passwd command
The passwd command is used to change passwords for user accounts. A normal
user may only change the password for his or her own account, while the superuser
may change the password for any account.
Options:
uname command
Options:
uname command:
Used to get the information about the current system (the name, version and other
details)
$uname
$ uname -s
$ uname -r
who command:
who command prints information about all users who are currently logged in.
Syntax:
who [OPTION]... [ FILE ] [ am i ]
find command:
find is one of the powerful utility of Unix (or Linux). It can search
the entire file-system to locate files and directories according to the specific
search criteria. Other than searching files in can also perform actions(executing
commands) on searched files.
Syntax:
$ find [option] [action]
Examples :
1 . File Type based Search:
>> The following command finds the file named Abc in current(.) directory and
all its sub-directories
Searches for the file Abc with any extension only in directories Dir1 and Dir2
4 . Size Based Search : Using find files can be searched based on its size .
>> To find the files with size more than 10Mb the command will be
./Abc.dat
./Abc
7 . Perform Action on the search result : Using exec option any action
(command)
can be executed on the search result.
>> To remove all the files having extension .swp from the current directory the
command will be :
bc command:
While used with files , bc starts by processing code from all the files listed on the
command line in the order listed. After all files have been processed, bc reads from
the standard input. All code is executed as it is read.
Example:
$ echo "2+5" | bc
tty command:
Prints the file name of the terminal connected in standard input.
Syntax : tty [OPTION]...
UNIX Text Editors
To write a program or a paper even to edit a mail message, you need to create,
write,store, retrieve, view, and edit files. In unix several text editors available for
this .
One of the first end-user programs hosted on the system and standardized in
UNIX-based systems ever since is the vi editor. ed is a line editor for the UNIX
operating system.
vi Editor:
vi (pronounced "vee-eye") is short for "vi"sual editor. It is a visual editor used to
create and edit text files.
It displays a window into the file being edited that shows 24 lines of text. vi lets
you add, change and delete text, but does not provide formatting capabilities like
centering lines or indenting paragraphs.
vi []
For cursor movement within the vi editor, we can not use the mouse . We have to
use key commands. To use a key command, user has to be in the command mode.
To go to command mode, press the Esc key.
The new or modified file is saved when user exits from vi. But it is also possible to
exit without saving the file.
To use a command to exit from vi , after pressing the Esc key ,colon : is to be
pressed.
The cursor moves to bottom of screen whenever a colon (:) is typed. This type of
command is completed by hitting the (or ) key.
I
insert text at beginning of current line,
until hit
a append text after cursor, until hit
A append text to end of current line,
until hit
o open and put text in a new line below
current line, until hit
O open and put text in a new line above
current line, until hit
UNIX FILE COMMANDS
In this module following important file handling commands will be discussed:
touch
cat
cat > (single redirection)
cat >>(double redirection)
cp
mv
cmp
comm
diff
touch command
Touch command is used in Unix to create an empty file.
Touch command is used to change the timestamps (access time and modification
time of a file).
cat command
Use of cat command:
'cat' command is used to display a file content.
Syntax:
$ cat data
This is an unix file
This is line two
$
cat with single redirection(cat >filename) , creates a new file if no file with the
given file name already exists and overrites the file if a file with given file name
already exists.
cat with double redirection (cat >>filename) appends the content given through
standard input to the file.
cp command
cp command is used to copy one file's content to another file.
Syntax: $ cp [source filename] [destination filename]
Switches:
1. cp -i [sourcefilename] [destination filename] This command copies the content
of a file interactively.
mv command
mv command is used for:
1. for renaming a file in same directory.
2. for moving a file to a different directory.
Syntax:
$ mv [sourcefilename] [destinationfilename]
$ mv [source_directory] [destination_directory]
Directory Commands:
Every item in the UNIX filesystem tree is either a file, or a directory. A directory is
like a file folder. A directory can contain files, and other directories. A directory
contained within another is called the child of the other. A directory in the
filesystem tree may have many children, but it can only have one parent. A file can
hold information, but cannot contain other files, or directories.
The place in the file system tree where an user is located is called the current
working directory (which can be listed using pwd command).
As a user logs in, user is put in his/her home directory.
ls Command
Lists the contents of any directory (current directory if no directory specified).
Sorts entries without option
$ ls [option(s)] [filename]
Syntax :
Syntax:
Example: To show only lines common between file1 and file2, command is
diff - This command is used to compare two files line by line. The output indicates
how the lines in each file are different, and the steps that will be involved in
changing file1 to file2.
The change commands are in the format [range][acd][range]. The range on the left
may be a line number or a comma-separated range of line numbers referring to
file1, and the range on the right similarly refers to file2. The character in the
middle indicates the action i.e. add, change or delete.
‘LaR’ – Add lines in range ‘R’ from file2 after line ‘L’ in file1.
‘FcT’ – Change lines in range ‘F’ of file1 to lines in range ‘T’ of file2.
‘RdL’ – Delete lines in range ‘R’ from file1 that would have appeared at
line ‘L’ in file2
Introduction to WinSCP
Step - B3 : Select the desired location from drop down list and select
copy
Saving sessions for future use
All the session information can be saved for future use and faster
access.
The information can be saved are :
>> Server IP
>> User name,
>> Password(Not recommended)
>> Communication protocol