Thursday, June 5, 2014

Basic Linux Commands for DBAs

General Linux Commands for DBAs

Displays current working directory
$ pwd
List the current directory contents
$ ls
 ls -l
List the current directory contents with extra details
$ ls -l
Displays files for the specified path
$ ls
 cd ~ / cd
User home directory
$ cd  / $ cd ~
 cd -
Previous current directory
$ cd -
Clear screen
$ clear
Creates an empty file
$ touch abc
Removes specified file
$ rm abc
 rm -rf
-f force -r recursive, Removes complete directory with its contents
$ rm -rf
 cp file1 file2
Creates a copy of file1 to file2, if destination is file it creates a duplicate copy, if destination is directory it moves the file into that directory.
$ cp file1 file2
 cp -r dir1 dir2
Creates a duplicate copy of whole directory
$ cp -r dir1 dir2
 mv file2 file3
Renames given file to new file
$ mv file2 file3
Displays contents of the file
$ cat file1.txt
Displays contents of the file page by page, for next page {Space}  to quit {q}
$ more file1.txt
Displays first 10 lines from the file
$ head file1.txt
$ head -20 file1.txt (first 20 lines)
Displays last 10 lines from the file
$ tail file1.txt
$ tail -20 file1.txt (last 20 lines)
 tail -f
Displays contents of the file as it grows, starting with last 10 lines, to quit {ctrl+c}
$ tail -f Kalyan2.err
Displays current date and time
$ date
Display help for the given command
$ man cat
 command > filename
Redirects output to specified filename
$ date > date.txt
 command >> filename
Appends the redirected output to existing file
$ date >> date.txt
 sort file1
Sort the contents of the file
$ sort file1
 | (Pipe)
Pipes the output to other command
$ cat file1 | sort
Displays all current processes
$ ps
Displays all running processes
$ top
Kills the process Id
$ kill
Displays current months calendar
$ cal
Displays current uptime
$ uptime
Displays who is online (All the users who are connected to this host)
$ w
Displays the current logged in user name
$ whoami
Displays information about the user
$ finger kalyan
Displays possible locations of the given application
$ whereis mysql
$ whereis perl
Displays which app runs
$ which mysql
$ which perl
Prints the system information
$ uname
 uname -a
Prints Kernel information
$ uname -a
 uname -o
Displays operating system
-o Operating System
-v Kernel version
-n Node Name
-m Machine
-p Processor
-a All
$ uname -o
Displays number of newlines, words and bytes in the file
$ ls -lrt | wc - l
Displays count for ls -lrt
Displays the name and value of each shell vairable
$ set
To view value in any environment variable
Displays all environment variable
$ printenv

No comments: