Difference between revisions of "Linux Commands"

From GWAVA Technologies Training
Jump to: navigation, search
(System Commands)
Line 24: Line 24:
 
  md [directory name]
 
  md [directory name]
 
  mkdir [directory name]
 
  mkdir [directory name]
 +
 +
===Copy a directory===
 +
Copy a directory recursively "R"
 +
cp -R "source" "destination"
  
 
===Remove a directory ===
 
===Remove a directory ===
Line 140: Line 144:
 
  nslookup "Enter"
 
  nslookup "Enter"
 
  server "Enter"
 
  server "Enter"
 +
 +
Clear DNS Cache
 +
rcnscd stop
 +
then
 +
rcnscd start
  
 
Trace the route to a server
 
Trace the route to a server
Line 147: Line 156:
 
  hostname
 
  hostname
  
Secure connect to another system
+
SSH
 +
Secure connect to another system, exit to leave ssh shell
 
  ssh [hostname or ip address]
 
  ssh [hostname or ip address]
  exit to leave ssh shell
+
 
 +
telnet
 +
Useful for testing connections. You can send a test email with it:
 +
  telnet [IP address or DNS hostname] [port]
 +
ehlo [ENTER]
 +
mail from:  retain@[your domain name]  (note: the "from" can actually be spoofed - it really can contain any text of user@domain.com)[ENTER]
 +
rcpt to: [yours or a user's email address][ENTER]
 +
data[ENTER]
 +
subject:  test email from telnet on Retain server[ENTER]
 +
This is a test[ENTER]
 +
.[ENTER]  (you are literally typing a "period" here and pressing [ENTER])
 +
quit[ENTER]
  
 
==Process Commands==
 
==Process Commands==
Line 157: Line 178:
 
Display an overview of the system resources can be used to find a process
 
Display an overview of the system resources can be used to find a process
 
  top
 
  top
 +
 +
Check runlevel of a process
 +
chkconfig [process name]
  
 
===Find a process===
 
===Find a process===
 
To find a running process you know the name of  
 
To find a running process you know the name of  
  ps aux | grep "process name"
+
  ps aux | grep [process name]
  
 
===Kill a process===
 
===Kill a process===
Line 167: Line 191:
 
It the process us hung you may have to be more forceful
 
It the process us hung you may have to be more forceful
 
  kill -9 [process ID]
 
  kill -9 [process ID]
 +
 +
===Who is logged in===
 +
Returns a list of logged in users if the TTY column shows "pts/3" that shows us that use is remotely logged in.
 +
who
 +
w
  
 
==Utilities==
 
==Utilities==

Revision as of 19:40, 23 November 2015

Useful Linux Commands

You can use man [command] to get information about a command, but that is more programmer oriented. You are generally better off going to a search engine and searching for [command] examples.

One of the great powers of Linux is being able to pipe | or redirect outputs from one command to another to do things.

You can also use these commands to create bash scripts.

Contents

Disk Commands

Returns a quick overview of what disks are mounted and how full they are in human readable formatting.

df -h

Directory Commands

Directory details

Returns an estimate of file space usage, in human readable format (k,M,G). Warning: May take a long time.

du -h

Returns a total size of the directories under where this command was run and sorts by size.

du -hsx * | sort -rh | head -10

Create a directory

Creates a directory

md [directory name]
mkdir [directory name]

Copy a directory

Copy a directory recursively "R"

cp -R "source" "destination"

Remove a directory

Removes a directory and its contents. Warning: irreversible, fast and dangerous if done in the wrong place with wrong switches. [1]

rm -r "directory"

Directory List

Return a list of files in a directory. This always works (shows file size in bytes)

ls -s

This is a SLES alias of the above

l

Display file size in human-readable values "-h" (K,M,G)

l -h

Sorted by size "S", ascending "r", human-readable "h"

l -Srh

Sorted by time "t", ascending "r", human-readable "h"

l -trh

Show hidden files "a", long list format "l", human-readable "h"

l -alh

Sorted by reverse chonological order l -qaltr

List all open files

lsof

Change Permissions

Permissions are a big deal in Linux [2] not so much in Windows.

Add read and write permissions to User and Group but only read to Other recursively "R" in the destination directory

chmod -R 664 /"destination"

Add Execute, read, and write permissions to User and Group but only read to Other recursively "R" in the destination directory

chmod -R 774 /"destination"

Change Ownership

Ownership of a directory can make a big difference in how Retain works

chown user:group directory/

Change the ownership recursively "R" to user tomcat and group tomcat of the logs directory in the current directory

chown -R tomcat:tomcat logs/

File Commands

Show the contents of a file

cat "filename"

Pipe through more to display a screen full of text at a time (space for next page, enter for next line, ctrl-c to break out)

cat "filename" | more

Pipe through less to display file in less.

cat "filename" | less

Find a file

Find a file from the root of the file system (aka looks everywhere for it) Warning: may take a long time.

find / -name "fileName"

Find all files with the string "log" as part of the filename.

find . | grep log

Find and recursively unzip all items in a directory structure called zippedDir to the current directory.

find /zippedDir -name "*.zip" -exec unzip {} \;

Find files in current directory older than 7 days and delete them.

find . -mtime +7 -exec rm {} \;

Find any file off the root and beyond that is larger than 20M:

find / -type f -size +20M -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'

Copy a file

cp origin /destination/file

To copy particular files recursively

cp -r *.txt /destination

To copy to the current directory

cp /software/origin.file .

To secure copy a file to a remote location

scp [source] [destination IP address]:[username]/[destination]

Sync a file or directory between locations, recurse "r" through subdirectories, retain "a" permissions, ownership and timestamps, verbose "v" logging to screen, show progress "P"

rsync -ravP [source] [destination]

Move a file

Moves file to the destination directory in verbose "v" mode.

mv -v "file" "destination"

Remove or delete a file

Removes a particular file

rm "file"

Change Permissions

Permissions are a big deal in Linux [3] not so much in Windows. Add execute "x" rights to all levels on all shell scripts in the current directory

chmod +x *.sh

Network

Download the Latest Version of Retain

wget "http://download.gwava.com/download.php?product=Retain&version=current"

Find the IP address of the server

ifconfig

look up mx records

host -t MX [domain.com]

Determine hosts

cat /etc/resolv.conf 

DNS

nslookup "Enter"
server "Enter"

Clear DNS Cache

rcnscd stop 

then

rcnscd start

Trace the route to a server

traceroute [domain.com]

Show the system name

hostname

SSH Secure connect to another system, exit to leave ssh shell

ssh [hostname or ip address]

telnet Useful for testing connections. You can send a test email with it:

telnet [IP address or DNS hostname] [port]
ehlo [ENTER]
mail from:  retain@[your domain name]  (note: the "from" can actually be spoofed - it really can contain any text of user@domain.com)[ENTER]
rcpt to: [yours or a user's email address][ENTER]
data[ENTER]
subject:  test email from telnet on Retain server[ENTER]
This is a test[ENTER]
.[ENTER]   (you are literally typing a "period" here and pressing [ENTER])
quit[ENTER]

Process Commands

Display memory usage

free -m

Display an overview of the system resources can be used to find a process

top

Check runlevel of a process

chkconfig [process name]

Find a process

To find a running process you know the name of

ps aux | grep [process name]

Kill a process

You have to find a runaway process with top or ps

kill [process ID]

It the process us hung you may have to be more forceful

kill -9 [process ID]

Who is logged in

Returns a list of logged in users if the TTY column shows "pts/3" that shows us that use is remotely logged in.

who
w

Utilities

Get a history of commands

history

To run a past command

![number of command to run from history]

To run a past command by name

![Ctrl-r][start typing desired command]
Personal tools
Namespaces

Variants
Actions
Home
Exchange
GroupWise
JAVA
Linux
MTK
Retain
GW Monitoring and Reporting (Redline)
GW Disaster Recovery (Reload)
GW Forensics (Reveal)
GWAVA
Secure Messaging Gateway
GW Mailbox Management (Vertigo)
Windows
Other
User Experience
Toolbox
Languages
Toolbox