PDA

View Full Version : Common Unix/Linux Commands used via Telnet



me1960
03-03-09, 10:28
Common Unix/Linux Commands used via Telnet


cd
When typed by itself, cd (”change directory”), will take you back to your $HOME directory

cd /path/to/directory
To change to a specific directory, type cd followed by the path to the directory. If it is a subdirectory of the current directory, you can just type the directory name.

cd ..
Typing cd .. moves you up one directory from your current location.

pwd
To see which directory you are in, type pwd (”print (display) working directory”).

exit
Just as it sounds, use exit to log out. Alternatively, you can type logout.

Creating and Deleting Directories

mkdir directoryname
To create a new directory, type mkdir (”make directory”) and specify the new directory’s name.

rmdir directoryname
To delete an empty directory, type rmdir (”remove directory”) and the directory’s name.

Listing Files

ls
To display a list of files and subdirectories in your current directory, type ls (”list”)

ls -a
To see a more complete list which includes hidden files or files that begin with a “.” (dot), type ls -a.

ls -la
To list all files and directories in long format which will provide details about each file and directory, type ls -la.

ls -lS
To list all directories and files, sorted by size, in long format, type ls -lS.

ls -lta
To list all files and directories in long format by time modified, type ls -lta.


Copying Files

cp oldfilename newfilename
Will copy the contents of one file to another file, resulting in two copies of the same file on your account.

cp directory/* destinationdirectory
Will copy the contents of one directory to another directory. Make sure you have created the destination directory before trying to copy files to it - see mkdir above. Results in two copies of the files on your account; one copy in the existing directory and another in the destination directory.

Searching FIles and Directories

find -name ‘n*’
The find command can be used to locate files or a group of files. It can also be used to display directories. The example given will find all file and directory names within the current directory and subdirectories of it that begin with the letter n. (You can also explore using the locate command - type info locate and/or man locate for usage information.)

grep -inw text filename
Can be used to locate text in a specific file or directory of files (use * in place of filename to search all of the files in the current directory). The -i argument indicates the search is to disregard cASe, the -n instructs to show the corresponding line number, and -w tells it to match only based on the whole word. (This doesn’t even begin to touch on the power of grep and its many uses. In addition to its searching capability, the grep command can be used in combination with other commands to act as a filter. It also allows the use of “wildcards”. Two other variations of grep are also available, egrep and fgrep. To begin your quest for more information, type man grep and/or info grep.)

Displaying / Comparing File Content

wc filename
Counts and displays the number of lines, number of words, and number of characters of the given file.

cat filename
Displays the entire contents of a file.

nl filename
Shows the content of the file, including line numbers (nl=number lines).

more filename
Displays the contents of a file one screen at a time. Press the SPACEBAR to display the next screen of text.

cmp filename1 filename2
Compares the contents of the two named files and reports the first different character found and the line number.

diff filename1 filename2
Compares the contents of the two named files and reports all of the differences found. (Can also be used for comparing the contents of two directories.)

Moving, Renaming, and Deleting Files

mv oldfilename newfilename
Can be used to rename a file (mv fileA fileB), move a file (mv fileA /dirA/), or both (mv fileA /dirB/fileB).

rm -i filename
Removes (deletes) the specified file. (The -i is not necessary, but is recommended as it will prompt you to confirm the action first. When prompted, type y to confirm or type n if you changed your mind.)

Changing Permissions

chmod permissions filename
Changes the permissions on a filename or directory as specified. For example, chmod 755 startup.sh.

Archives and Compression

tar -cfv filename.tar directoryname
To archive a directory and all of its contents including subdirectories, navigate to where the directory is located and type the above command, replacing filename.tar with the name you wish to give the archive file and directoryname with the name of the directory you wish to archive. Alternatively, you can archive a select group of individual files (or directories) by specifying each file name in place of directoryname separated by spaces, like tar -cvf filename.tar fileA fileB fileC. Note: When creating a tar file (aka “tarball”) be sure to specify the name you wish to give the tar file! (TAR indicates Tape ARchive, as it was originally a tape archiving program. The -c means “create”, v means “verbose” (which basically says tell me what you’re doing), and the f indicates that a filename will follow (filename.tar)).

tar -tvf filename.tar
Typing this command will result in a list of the contents of the tar file. This is generally a good thing to do before unpacking the tar file to be sure there are no matching filenames which will result in files being unintentionally overwritten.

tar -xvf filename.tar
You can see the similarities to the command used to tar the file. This time, though, you use -x to “extract” instead of the -c used to create. You can also extract only certain select files (or directories) by specifying the individual names, separated by spaces, after the tar filename, such as tar -xvf filename.tar fileA fileC

gzip filename.tar
This utility, gzip (gnu zip), is used for compression. Normally, when you wish to compress a set of files, you willtar them first then compress them using this command. In doing so, the filename will automatically change from filename.tar to filename.tar.gz (appending .gz to the file extension).

gunzip filename.tar.gz
This command (g”unzip”) is used to uncompress a .tar.gz file, which will also result in the filename being changed back to filename.tar. Once it has been uncompressed, you can then untar it using the tar command above. (Alternatively, you can use gzip -d (for “decompress”) in place of gunzip.)

tar -czvf filename.tgz directoryname
This command, which uses a z switch (”zip”), allows you to take a bit of a shortcut instead of using the tar and gzip commands separately. The example will result in a compressed archive named filename.tgz.

tar -xzvf filename.tgz
This command is used to uncompress and extract the files from a .tgz archive.

me1960
05-05-09, 17:53
An A-Z Index of the Bash command line for Linux.

alias (http://www.ss64.com/bash/alias.html) Create an alias
apropos Search Help manual pages (man -k)
apt-get (http://www.debian.org/doc/manuals/apt-howto/ch-apt-get.en.html) Search for and install software packages (Debian)
aspell (http://aspell.net/) Spell Checker
awk (http://www.ss64.com/bash/awk.html) Find and Replace text, database sort/validate/index
b
bash GNU Bourne-Again SHell
bc (http://www.ss64.com/bash/bc.html) Arbitrary precision calculator language
bg (http://www.ss64.com/bash/bg.html) Send to background
break (http://www.ss64.com/bash/break.html) Exit from a loop
builtin (http://www.ss64.com/bash/builtin.html) Run a shell builtin
bzip2 (http://www.bzip.org/) Compress or decompress named file(s)
c
cal (http://www.ss64.com/bash/cal.html) Display a calendar
case (http://www.ss64.com/bash/case.html) Conditionally perform a command
cat (http://www.ss64.com/bash/cat.html) Display the contents of a file
cd (http://www.ss64.com/bash/cd.html) Change Directory
cfdisk (http://www.ss64.com/bash/cfdisk.html) Partition table manipulator for Linux
chgrp (http://www.ss64.com/bash/chgrp.html) Change group ownership
chmod (http://www.ss64.com/bash/chmod.html) Change access permissions
chown (http://www.ss64.com/bash/chown.html) Change file owner and group
chroot (http://www.ss64.com/bash/chroot.html) Run a command with a different root directory
chkconfig (http://www.ss64.com/bash/chkconfig.html) System services (runlevel)
cksum (http://www.ss64.com/bash/cksum.html) Print CRC checksum and byte counts
clear Clear terminal screen
cmp (http://www.ss64.com/bash/cmp.html) Compare two files
comm (http://www.ss64.com/bash/comm.html) Compare two sorted files line by line
command (http://www.ss64.com/bash/command.html) Run a command - ignoring shell functions
continue (http://www.ss64.com/bash/continue.html) Resume the next iteration of a loop
cp (http://www.ss64.com/bash/cp.html) Copy one or more files to another location
cron (http://www.ss64.com/bash/cron.html) Daemon to execute scheduled commands
crontab (http://www.ss64.com/bash/crontab.html) Schedule a command to run at a later time
csplit (http://www.ss64.com/bash/csplit.html) Split a file into context-determined pieces
cut (http://www.ss64.com/bash/cut.html) Divide a file into several parts
d
date (http://www.ss64.com/bash/date.html) Display or change the date & time
dc (http://www.ss64.com/bash/dc.html) Desk Calculator
dd (http://www.ss64.com/bash/dd.html) Convert and copy a file, write disk headers, boot records
ddrescue (http://www.ss64.com/bash/ddrescue.html) Data recovery tool
declare (http://www.ss64.com/bash/declare.html) Declare variables and give them attributes
df (http://www.ss64.com/bash/df.html) Display free disk space
diff (http://www.ss64.com/bash/diff.html) Display the differences between two files
diff3 (http://www.ss64.com/bash/diff3.html) Show differences among three files
dig (http://www.ss64.com/bash/dig.html) DNS lookup
dir (http://www.ss64.com/bash/dir.html) Briefly list directory contents
dircolors (http://www.ss64.com/bash/dircolours.html) Colour setup for `ls'
dirname (http://www.ss64.com/bash/dirname.html) Convert a full pathname to just a path
dirs (http://www.ss64.com/bash/dirs.html) Display list of remembered directories
dmesg (http://www.ss64.com/bash/dmesg.html) Print kernel & driver messages
du (http://www.ss64.com/bash/du.html) Estimate file space usage
e
echo (http://www.ss64.com/bash/echo.html) Display message on screen
egrep (http://www.ss64.com/bash/egrep.html) Search file(s) for lines that match an extended expression
eject (http://www.ss64.com/bash/eject.html) Eject removable media
enable (http://www.ss64.com/bash/enable.html) Enable and disable builtin shell commands
env (http://www.ss64.com/bash/env.html) Environment variables
ethtool Ethernet card settings
eval (http://www.ss64.com/bash/eval.html) Evaluate several commands/arguments
exec (http://www.ss64.com/bash/exec.html) Execute a command
exit (http://www.ss64.com/bash/exit.html) Exit the shell
expect (http://en.wikipedia.org/wiki/Expect) Automate arbitrary applications accessed over a terminal
expand (http://www.ss64.com/bash/expand.html) Convert tabs to spaces
export (http://www.ss64.com/bash/export.html) Set an environment variable
expr (http://www.ss64.com/bash/expr.html) Evaluate expressions
f
false (http://www.ss64.com/bash/false.html) Do nothing, unsuccessfully
fdformat (http://www.ss64.com/bash/fdformat.html) Low-level format a floppy disk
fdisk (http://www.ss64.com/bash/fdisk.html) Partition table manipulator for Linux
fg (http://www.ss64.com/bash/fg.html) Send job to foreground
fgrep (http://www.ss64.com/bash/fgrep.html) Search file(s) for lines that match a fixed string
file Determine file type
find (http://www.ss64.com/bash/find.html) Search for files that meet a desired criteria
fmt (http://www.ss64.com/bash/fmt.html) Reformat paragraph text
fold (http://www.ss64.com/bash/fold.html) Wrap text to fit a specified width.
for (http://www.ss64.com/bash/for.html) Expand words, and execute commands
format Format disks or tapes
free Display memory usage
fsck (http://www.ss64.com/bash/fsck.html) File system consistency check and repair
ftp File Transfer Protocol
function (http://www.ss64.com/bash/function.html) Define Function Macros
fuser (http://www.ss64.com/bash/fuser.html) Identify/kill the process that is accessing a file
g
gawk (http://www.ss64.com/bash/awk.html) Find and Replace text within file(s)
getopts (http://www.ss64.com/bash/getopts.html) Parse positional parameters
grep (http://www.ss64.com/bash/grep.html) Search file(s) for lines that match a given pattern
groups (http://www.ss64.com/bash/groups.html) Print group names a user is in
gzip (http://www.ss64.com/bash/gzip.html) Compress or decompress named file(s)
h
hash (http://www.ss64.com/bash/hash.html) Remember the full pathname of a name argument
head (http://www.ss64.com/bash/head.html) Output the first part of file(s)
history (http://www.ss64.com/bash/history.html) Command History
hostname (http://www.ss64.com/bash/hostname.html) Print or set system name
i
id (http://www.ss64.com/bash/id.html) Print user and group id's
if (http://www.ss64.com/bash/if.html) Conditionally perform a command
ifconfig (http://www.ss64.com/bash/ifconfig.html) Configure a network interface
ifdown (http://www.ss64.com/bash/ifup.html) Stop a network interface
ifup (http://www.ss64.com/bash/ifup.html) Start a network interface up
import (http://www.ss64.com/bash/import.html) Capture an X server screen and save the image to file
install (http://www.ss64.com/bash/install.html) Copy files and set attributes
j
join (http://www.ss64.com/bash/join.html) Join lines on a common field
k
kill (http://www.ss64.com/bash/kill.html) Stop a process from running
killall Kill processes by name
l
less (http://www.ss64.com/bash/less.html) Display output one screen at a time
let (http://www.ss64.com/bash/let.html) Perform arithmetic on shell variables
ln (http://www.ss64.com/bash/ln.html) Make links between files
local (http://www.ss64.com/bash/local.html) Create variables
locate (http://www.ss64.com/bash/locate.html) Find files
logname (http://www.ss64.com/bash/logname.html) Print current login name
logout (http://www.ss64.com/bash/logout.html) Exit a login shell
look (http://www.ss64.com/bash/look.html) Display lines beginning with a given string
lpc (http://www.ss64.com/bash/lpc.html) Line printer control program
lpr (http://www.ss64.com/bash/lpr.html) Off line print
lprint Print a file
lprintd Abort a print job
lprintq List the print queue
lprm (http://www.ss64.com/bash/lprm.html) Remove jobs from the print queue
ls (http://www.ss64.com/bash/ls.html) List information about file(s)
lsof (http://www.ss64.com/bash/lsof.html) List open files
m
make Recompile a group of programs
man (http://www.ss64.com/bash/man.html) Help manual
mkdir (http://www.ss64.com/bash/mkdir.html) Create new folder(s)
mkfifo (http://www.ss64.com/bash/mkfifo.html) Make FIFOs (named pipes)
mkisofs Create an hybrid ISO9660/JOLIET/HFS filesystem
mknod (http://www.ss64.com/bash/mknod.html) Make block or character special files
more (http://www.ss64.com/bash/more.html) Display output one screen at a time
mount (http://www.ss64.com/bash/mount.html) Mount a file system
mtools (http://www.ss64.com/bash/mtools.html) Manipulate MS-DOS files
mv (http://www.ss64.com/bash/mv.html) Move or rename files or directories
mmv (http://www.ss64.com/bash/mmv.html) Mass Move and rename (files)
n
netstat Networking information
nice (http://www.ss64.com/bash/nice.html) Set the priority of a command or job
nl (http://www.ss64.com/bash/nl.html) Number lines and write files
nohup (http://www.ss64.com/bash/nohup.html) Run a command immune to hangups
nslookup (http://www.ss64.com/bash/nslookup.html) Query Internet name servers interactively
o
open (http://www.ss64.com/bash/open.html) Open a file in its default application
op (http://www.ss64.com/bash/op.html) Operator access
p
passwd (http://www.ss64.com/bash/passwd.html) Modify a user password
paste (http://www.ss64.com/bash/paste.html) Merge lines of files
pathchk Check file name portability
ping (http://www.ss64.com/bash/ping.html) Test a network connection
pkill (http://www.ss64.com/bash/pkill.html) Stop processes from running
popd (http://www.ss64.com/bash/popd.html) Restore the previous value of the current directory
pr (http://www.ss64.com/bash/pr.html) Prepare files for printing
printcap Printer capability database
printenv Print environment variables
printf (http://www.ss64.com/bash/printf.html) Format and print data
ps (http://www.ss64.com/bash/ps.html) Process status
pushd (http://www.ss64.com/bash/pushd.html) Save and then change the current directory
pwd (http://www.ss64.com/bash/pwd.html) Print Working Directory
q
quota (http://www.ss64.com/bash/quota.html) Display disk usage and limits
quotacheck (http://www.ss64.com/bash/quotacheck.html) Scan a file system for disk usage
quotactl (http://www.ss64.com/bash/quotactl.html) Set disk quotas
r
ram (http://www.ss64.com/bash/ram.html) ram disk device
rcp (http://www.ss64.com/bash/rcp.html) Copy files between two machines
read (http://www.ss64.com/bash/read.html) read a line from standard input
readonly (http://www.ss64.com/bash/readonly.html) Mark variables/functions as readonly
reboot Reboot the system
renice Alter priority of running processes
remsync Synchronize remote files via email
return (http://www.ss64.com/bash/return.html) Exit a shell function
rev (http://www.ss64.com/bash/rev.html) Reverse lines of a file
rm (http://www.ss64.com/bash/rm.html) Remove files
rmdir (http://www.ss64.com/bash/rmdir.html) Remove folder(s)
rsync (http://www.ss64.com/bash/rsync.html) Remote file copy (Synchronize file trees)
s
screen (http://www.ss64.com/bash/screen.html) Multiplex terminal, run remote shells via ssh
scp (http://www.ss64.com/bash/scp.html) Secure copy (remote file copy)
sdiff (http://www.ss64.com/bash/sdiff.html) Merge two files interactively
sed (http://www.ss64.com/bash/sed.html) Stream Editor
select (http://www.ss64.com/bash/select.html) Accept keyboard input
seq (http://www.ss64.com/bash/seq.html) Print numeric sequences
set (http://www.ss64.com/bash/set.html) Manipulate shell variables and functions
sftp Secure File Transfer Program
shift (http://www.ss64.com/bash/shift.html) Shift positional parameters
shopt (http://www.ss64.com/bash/shopt.html) Shell Options
shutdown (http://www.ss64.com/bash/shutdown.html) Shutdown or restart linux
sleep (http://www.ss64.com/bash/sleep.html) Delay for a specified time
slocate (http://www.ss64.com/bash/slocate.html) Find files
sort (http://www.ss64.com/bash/sort.html) Sort text files
source (http://www.ss64.com/bash/source.html) Run commands from a file `.'
split (http://www.ss64.com/bash/split.html) Split a file into fixed-size pieces
ssh (http://en.wikipedia.org/wiki/Secure_Shell) Secure Shell client (remote login program)
strace Trace system calls and signals
su (http://www.ss64.com/bash/su.html) Substitute user identity
sudo (http://www.ss64.com/bash/sudo.html) Execute a command as another user
sum (http://www.ss64.com/bash/sum.html) Print a checksum for a file
symlink (http://www.ss64.com/bash/symlink.html) Make a new name for a file
sync (http://www.ss64.com/bash/sync.html) Synchronize data on disk with memory
t
tail (http://www.ss64.com/bash/tail.html) Output the last part of files
tar (http://www.ss64.com/bash/tar.html) Tape ARchiver
tee (http://www.ss64.com/bash/tee.html) Redirect output to multiple files
test (http://www.ss64.com/bash/test.html) Evaluate a conditional expression
time (http://www.ss64.com/bash/time.html) Measure Program running time
times (http://www.ss64.com/bash/times.html) User and system times
touch (http://www.ss64.com/bash/touch.html) Change file timestamps
top (http://www.ss64.com/bash/top.html) List processes running on the system
traceroute (http://www.ss64.com/bash/traceroute.html) Trace Route to Host
trap Run a command when a signal is set(bourne)
tr (http://www.ss64.com/bash/tr.html) Translate, squeeze, and/or delete characters
true (http://www.ss64.com/bash/true.html) Do nothing, successfully
tsort (http://www.ss64.com/bash/tsort.html) Topological sort
tty (http://www.ss64.com/bash/tty.html) Print filename of terminal on stdin
type (http://www.ss64.com/bash/type.html) Describe a command
u
ulimit (http://www.ss64.com/bash/ulimit.html) Limit user resources
umask (http://www.ss64.com/bash/umask.html) Users file creation mask
umount Unmount a device
unalias (http://www.ss64.com/bash/alias.html) Remove an alias
uname (http://www.ss64.com/bash/uname.html) Print system information
unexpand (http://www.ss64.com/bash/unexpand.html) Convert spaces to tabs
uniq (http://www.ss64.com/bash/uniq.html) Uniquify files
units (http://www.ss64.com/bash/units.html) Convert units from one scale to another
unset (http://www.ss64.com/bash/unset.html) Remove variable or function names
unshar (http://www.ss64.com/bash/unshar.html) Unpack shell archive scripts
until (http://www.ss64.com/bash/until.html) Execute commands (until error)
useradd (http://www.ss64.com/bash/useradd.html) Create new user account
usermod (http://www.ss64.com/bash/usermod.html) Modify user account
users (http://www.ss64.com/bash/users.html) List users currently logged in
uuencode (http://www.ss64.com/bash/uuencode.html) Encode a binary file
uudecode (http://www.ss64.com/bash/uuencode.html) Decode a file created by uuencode
v
v Verbosely list directory contents (`ls -l -b')
vdir Verbosely list directory contents (`ls -l -b')
vi (http://www.ss64.com/bash/vi.html) Text Editor
vmstat (http://www.ss64.com/bash/vmstat.html) Report virtual memory statistics
w
watch (http://www.ss64.com/bash/watch.html) Execute/display a program periodically
wc (http://www.ss64.com/bash/wc.html) Print byte, word, and line counts
whereis (http://www.ss64.com/bash/whereis.html) Report all known instances of a command
which (http://www.ss64.com/bash/which.html) Locate a program file in the user's path.
while (http://www.ss64.com/bash/while.html) Execute commands
who (http://www.ss64.com/bash/who.html) Print all usernames currently logged in
whoami (http://www.ss64.com/bash/whoami.html) Print the current user id and name (`id -un')
Wget Retrieve web pages or files via HTTP, HTTPS or FTP
write (http://www.ss64.com/bash/write.html) Send a message to another user
x
xargs (http://www.ss64.com/bash/xargs.html) Execute utility, passing constructed argument list(s)
yes (http://www.ss64.com/bash/yes.html) Print a string until interrupted
. (http://www.ss64.com/bash/source.html) Run a command script in the current shell
### (http://www.ss64.com/bash/rem.html) Comment / Remark

me1960
26-05-09, 13:09
Useful Telnet and CLI commands for Dm and Linux servers

When you Telnet your box or make a SSH connection shell to your Linux server, these commands are useful for you:
1-Show me who is online, which IP and which Gbox Version is running:
cat /var/tmp/share.onl

2- Show me all Distance 1 cards:
grep "dist:1" /var/tmp/share.info

3- Show me all Distance 1 cards and resolve the Provider ID:
for i in `grep 'dist:1' /var/tmp/share.info | awk '{print $6}' | sort` ; do grep "^$i" /var/keys/ident.info ; done

4-remove the Windows carriage returns ^M on Textfiles:
tr -s "\r" "\n" < winfile > unixfile

5-Showing the ident.info file in a nice way:
first CD to /var/keys
then:
cat ident.info | cut -c 1-9,19-196 > ident.info.new

and you will see the providers lije this example:
01000000;S0 - Mediaguard CAID
01000002;(Old)S1 - Orbit (1W/26E)
01000003;(Old)S1 - Canal+ France (19E)

6-With this command, you can also see if gbox process is running:
ps -ef

7- To start cs2gbox:
cd /var/bin/
./cs2gbox &

8- To start gbox:
cd /var/bin/
./gbox&

9- To start cs2gbox and gbox together in Gemini:
/var/script/gbox_cam.sh start

10-To stop cs2gbox:
killall cs2gbox

11- To stop gbox:
killall gbox

12- To chmod binary:
chmod 755 <filename>

13- To see number of cards from a peer :
cd /tmp/
grep <peer domain> share.info | wc -l

14- To see cards from a peer with distance and level:
cd /tmp/
grep <peer domain> share.info

15- To see peer status:
cd /tmp/
more share.onl
(Lines beginning with 1 are online peers, Lines beginning with 0 are offline peers)

16- To see number of cards with level X where X = number
cd /tmp/
grep Lev:X share.info | wc -l

17- To see number of cards with level X for a certain peer where X = number
cd /tmp/
grep <peer domain> share.info | grep Lev:X | wc -l

18- To see number of cards at distance X where X = number
cd /tmp/
grep dist:X share.info | wc -l

19- To see number of cards with distance X for a certain peer where X = number
cd /tmp/
grep <peer domain> share.info | grep dist:X | wc -l

20-rebooting your server:
reboot

21- changing your server login password (Very important):
passwd

22-For editing files:
vi <filename}
example:
vi /var/keys/cwshare.cfg

me1960
26-05-09, 13:41
Ban cccam users in iptables


Here is a little command to get formated iptable rules to ban deleted cccam users:

cat /var/log/cccam.warn | awk '{printf "-A INPUT -s %s -j REJECT \n", $5}' | awk 'x[$0]++ == 0'


the cccam.warn file is from "LOG WARNINGS" parameter in CCcam.cfg .

in CCcam.cfg:
LOG WARNINGS : /var/log/cccam.warn



touch /var/log/cccam.warn