Previous Thread
Next Thread
Print Thread
Rate Thread
#16478 02/19/04 09:00 AM
Joined: Mar 2002
Posts: 815
S
nobody
OP Offline
nobody
S
Joined: Mar 2002
Posts: 815
Post your favorite tips and tricks that help make your life in the shell easier.

for i in ls *gz ; do tar -zxvf $i ; done

decompresses all the archives in a directory.

#16479 02/19/04 04:59 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
ls = list files
ls -a = list all files, including hidden
ls -hal = list all files, including hidden, with details in a human readable format

rm = remove, for removing a file
rmdir = remove, for removing a directory
rm -rf [directory]/ = remove and format, for removing a directory with data.


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16480 02/19/04 05:18 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
-Ar -u[user] -p --auto-repair = have MySQL repair all databases.

service [service] restart = Restart specifide sevice
service [service] stop = Stop specifide service
service [service] start = Start specifide service

du -h --max-depth=1 = Check (by directory) where all your space is at.

su = change user
make && make install = install script

cd /home/virtual;for c in site*;do cat $c/info/current/ipinfo|grep ipaddrs;done = Check what IP's are linked to what user accounts (I work for a webhost, I have to know it)

EditVirtDomain -c ipinfo,namebased=0,ipaddrs=[1.2.3.4] -D domain.com = Change name based domain to IP based.

EditVirtDomain -c ipinfo,namebased=1,ipaddrs=[] -D domain.com = Change IP based site to Name Based.

ntpdate time.windows.com = Sync time with Microsoft

If you have subdomain issues or need to add one their located in /etc/httpd/conf/subdomains.conf


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16481 02/19/04 05:24 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
If user is having an issue with Perl or PHP interpreters within the ensim service do the following:

sitelookup -s [username]
sitelookup -d [domainname]

(be sure they match up, we're compairing the server validations of where the username belongs and where the domain name belongs to be sure we aren't working with the wrong account)

cd /home/virtual/[username]/fst/var/www
ls

(we're trying to see if the interpreters directory exists, which it should, otherwise skip this step and the next step's RM)

ls interpreters

(If interpreters show up then there isn't a problem, if not, continue)

rmdir interpreters
DisableVirtDomain [domain]
EnableVirtDomain [domain]

(Here you tell the system to remove the interpreters directory, disable the account on the system, enable the account on the system. Re-enabling causes the Ensim service to rebuild all data).

ls interpreters

(interpreters should now exist, user account should now be able to use their account once again)


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16482 02/19/04 05:25 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
tar -cvzf [archivename].tgz /path/to/archive/ = Archive path to a .tgz file.

tar -cvzf [archivename].tgz /path/to/archive/ --exclude=/path/to/archive/yet/leave/out/ = Archive path to a .tgz file BUT leave out second path of files.


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16483 02/19/04 06:53 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
./end sysadmin guide

lol, I have to memorise pretty much all of that for work ;-x...


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16484 02/19/04 07:53 PM
Joined: Sep 2002
Posts: 390
UGN Member
Offline
UGN Member
Joined: Sep 2002
Posts: 390
su and sudo ....they are the biggest time savers in the universe


"The secret to creativity is knowing how to hide your sources."
-Albert Einstein

Tech Ninja Security
#16485 02/19/04 08:04 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
su [username] = change usernames. Some systems don't allow direct login to the root user so you need to su to the username.

sudo = used for giving users access to commands without actually giving them access to commands... Example: "sudo su -" can be set to log the user as root without needing password :glares at drak:


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16486 02/19/04 08:25 PM
Joined: Mar 2002
Posts: 815
S
nobody
OP Offline
nobody
S
Joined: Mar 2002
Posts: 815
ok I wasnt really looking for a description of bash commands... more like combinations of them.
I think there is already a post here containing basic bash commands.
*rm -rf = remove recurisive and force

dmesg | grep [device name]

outputs boot hardware information about a specific device useful for troubleshooting kernel problems. If the device is CD it will spit out info about your CD roms if you use hd as the device it will tell you about your harddrives

cat /var/log/XFree86.0.log | grep EE

outputs any errors from your xconfig log. makes troubleshooting X hella easier or switch EE with WW to view warnings.

#16487 03/01/04 07:02 PM
Joined: Jun 2002
Posts: 207
Member
Offline
Member
Joined: Jun 2002
Posts: 207
i always find myself using "locate [file] | grep [bin|png]" or whatever file i'm looking for
usually either when i'm looking for icons to use i'll do like "locate ethereal | grep png" or when trying to find where a program runs from, "locate mysql | grep bin"
enormous timesavers just b/c i don't pay as much attention as i should when i install stuff. well, i make sure i install it right, but about 4 hours later i forget where that was, lol
and of course, ps -aux | grep [program name]
speaking of which, i'm trying to find a way to pipe a process id into kill....but i can't figure it out. kill always comes back with an error everytime i try. i figure it'd be a huge timesaver if i can just write up a shell script where i just type in like "slackill [program]" and by going through ps and grep and cut and kill....it'll kill the process for me//


Unbodied unsouled unheard unseen
Let the gift be grown in the time to call our own
Truth is natural like a wind that blows
Follow the direction no matter where it goes
Let the truth blow like a hurricane through me
#16488 03/02/04 02:23 AM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
Okay this may soud ignorant, How do I restart my system from the commandline. I got rid of my GUI on my webserver and I just use bash now.

#16489 03/02/04 02:58 AM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
restart :x


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16490 03/02/04 08:33 AM
Joined: Mar 2002
Posts: 1,041
I
UGN Elite Poster
Offline
UGN Elite Poster
I
Joined: Mar 2002
Posts: 1,041
or

# reboot

or

# shutdown -r now

#16491 03/02/04 10:18 AM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
shutdown -r now


that is the one I was thinking of. Thanx

#16492 03/02/04 11:57 AM
Joined: Mar 2002
Posts: 1,136
P
UGN Elite Poster
Offline
UGN Elite Poster
P
Joined: Mar 2002
Posts: 1,136
just be careful...I did

shutdown now -r

once, and it shut down the server in Denver. My boss wasn't happy

#16493 03/02/04 12:02 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
hahaha, don't execute shutdown, it shuts down... note that you have to have autologin setup if you're maintianing the server remotely, otherwise when it boots it'll ask for the root user to login wink


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16494 03/02/04 01:30 PM
Joined: Mar 2002
Posts: 815
S
nobody
OP Offline
nobody
S
Joined: Mar 2002
Posts: 815
Gollum try using pidof [process] instead of ps

#16495 03/02/04 10:03 PM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
Your shiting me. lol. Well I have a stand alone server.

#16496 03/02/04 11:50 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
Yeh well I have 18 rackmounts wink ... all with autologin though heh...


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16497 03/03/04 04:01 AM
Joined: Mar 2002
Posts: 1,136
P
UGN Elite Poster
Offline
UGN Elite Poster
P
Joined: Mar 2002
Posts: 1,136
What? No, you can just ssh in. It doesn't need to automatically login. It just needs to start up whatever services you want, including ssh, and then you can connect and control it remotely.

#16498 03/19/04 11:06 PM
Joined: Jun 2002
Posts: 207
Member
Offline
Member
Joined: Jun 2002
Posts: 207
just a question on the first one. doing:
for i in ls *gz
wouldn't that use 'ls' as a value for i.
i think the correct way would to leave out the ls and just do
for i in *gz
that should load all files in the current directory for i, as the for command looks for files anyway. thus the ls should not be needed.//


Unbodied unsouled unheard unseen
Let the gift be grown in the time to call our own
Truth is natural like a wind that blows
Follow the direction no matter where it goes
Let the truth blow like a hurricane through me
#16499 03/21/04 02:46 PM
Joined: Jun 2002
Posts: 207
Member
Offline
Member
Joined: Jun 2002
Posts: 207
these are shell scripts i had to write:

used this one when after converting rtf files to html, i had to move and rename them. well i didn't have to rename them, but i did b/c it made me feel better. the filenames were .rtf.html, and i wanted just .html
moving multiple files and renaming them:

#!/bin/bash
for x in *.rtf.html #lists all converted html files in current directory
do
i=$(ls $x | cut -d. -f 1) #displays the filename up to the first period.
#for most files (in my case all of them) this will be the filename minus the extension
echo "Moving $i..."
mv $i.rtf.html /www/htdocs/$i.html #copy (or move, if you'd like to do that instead) all files to another directory and rename them
done


this second one i used to automatically generate a page of links to the files i just copied:

#!/bin/bash
rm index.html
for x in *.html
do
i=$(ls $x | cut -d. -f 1)
echo "<a href=$x>$i</a>
" >> index.html
done

pretty self explanatory. note that x is the full filename, and i is the filename without the extension.

i was setting up a large text section on my website, and so i used these two scripts in a cron job while having another program converting lots and lots of rtf files to html. it took a fairly long time, and so i set these up, so ppl could read the texts as they were generated and not have to wait for all of them to complete. speaking of which. does anyone know a really good rtf to html converter. i downloaded one that uses php. and yes it works. but it bloats the files big time. some of them end up being like 400-500k when all they need is 100k or so. needless to say very inefficient, especially when hosting from a cable connection. so if anyone has had any good results with certain conversion utilities, feel free to let me know.//


Unbodied unsouled unheard unseen
Let the gift be grown in the time to call our own
Truth is natural like a wind that blows
Follow the direction no matter where it goes
Let the truth blow like a hurricane through me
#16500 05/21/04 01:46 PM
Joined: Mar 2002
Posts: 815
S
nobody
OP Offline
nobody
S
Joined: Mar 2002
Posts: 815
Process Control

Something I find really useful especially logging in remotely is process controll. I might be explaining the ctrl-alt-del of unix here, but it was something I didnt figure out for like a year into my *nix life.

ctrl-c - kills a process
ctrl-z - stops or pauses a process and puts it in the background
& - launches a process into the background when it follows the command. ie: 'tail /var/log/apache/accesslog &' will write out new entries to the log file to your term window while you use it for other things
fg - places a stopped task into the foreground
bg - places a stopped task into the background

I find this usefull on bitchx or other command line irc clients that i can stop them, work in my shell, then resume chatting on irc. I also find & usefull for compiling programs. Send:
./configure && make && make install &
into the background as a background process and free up your term while it compiles and installs.

#16501 05/27/04 10:27 PM
Joined: May 2004
Posts: 3
W
Junior Member
Offline
Junior Member
W
Joined: May 2004
Posts: 3
Quote:
Gollum try using pidof [process] instead of ps
Thanks, that worked nicely sinetific.
Code
bye=`pidof xscreensaver` && kill $bye && echo proccess dies &#0124;&#0124; echo no such process
One of my favorites about bash is aliases.
Code
# emerge aliases
alias emask="echo `$1` /etc/portage/package.keywords"
alias es="emerge -s"                                                   
alias ep="emerge -pv"
alias e="sudo emerge"
alias emerge='sudo emerge'
    
# directory aliases                                                    
alias ..='cd ..'                                                       
alias ...='cd ../..'                                                   
alias ....='cd ../../..'                                               
alias c="clear"
alias cb="bash_issue"
alias ls="ls --color=always"
alias ll="ls --color -l"                                               
    
# misc aliases
alias grep='grep --colour=auto'                                        
alias killwine="killall -9 wine; killall -9 wineserver"                
alias recal="history | grep `$1`"                                      
alias lock='xscreensaver-command -lock'                                
alias r00t='sudo -s -H'  
alias svi='sudo vim'
alias smv='sudo mv'
alias vi="vim"                                                         
alias nat="nautilus --no-desktop"                                      
alias 3d="sudo 3ddeskd  --acquire 700 2>1&"                            
alias screengrab="import -window root ~/screen.jpg"                    
alias lvim='vim -c "normal '\''0"'                                     
alias mkisofs="mkisofs -rJV"
alias torrget="btdownloadcurses.py --minport 50555 --maxport 65500"    
alias cal2="cal -3; echo -e Todays date is `date +%B\ %d`"             
alias scr="screen -r"
alias scl="screen -list"
alias nm="nmap -sS -O -PI -PT"
alias icq="screen -S icq centericq"
alias irc="screen -S irc irssi"
alias mp3="cd ~/music/full-albums/ && screen -S mp3 cplay"
alias get="cd ~/download/torrent-files/ && screen -S get"


I sig not

Link Copied to Clipboard
Member Spotlight
Posts: 43
Joined: November 2002
Forum Statistics
Forums41
Topics33,840
Posts68,858
Average Daily Posts1
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Where and how do you torrent?
by danni75 - 03/01/24 05:58 AM
Animation,
by JohanKaariainen - 08/15/19 01:18 AM
Blackbeard.....
by Gremelin - 10/03/18 07:02 PM
my old account still exists!
by Crime - 08/10/18 02:47 PM
Okay WTF?
by HenryMiring - 09/27/17 01:45 AM
The History Thread...
by Gremelin - 08/11/17 12:11 PM
My friend NEEDS your HELP!
by Lena01 - 07/21/17 12:06 AM
I'm having fun with this guy.
by gabithompson730 - 07/20/17 01:50 AM
I want to upgrade my phone
by gabithompson730 - 07/20/17 01:49 AM
Doom 3
by Cyrez - 09/11/14 08:58 PM
Amazon Gift Card Generator/KeyGen?te
by Gecko666 - 08/22/14 09:21 AM
AIM scene 99-03
by lavos - 09/02/13 08:06 AM
Planetside 2
by Crime - 03/04/13 07:10 AM
Beta Testers Wanted
by Crime - 03/04/13 06:55 AM
Hello Everyone
by Gremelin - 02/12/12 06:01 PM
Tracfone ESN Generator
by Zanvin Green - 01/18/12 01:31 PM
Python 3 issue
by Testing - 12/17/11 09:28 PM
tracfone airtime
by Drache86 - 07/30/11 03:37 AM
Backdoors and the Infinite
by ZeroCoolStar - 07/10/11 03:52 AM
HackThisZIne #12 Releaseed!
by Pipat2 - 04/28/11 09:20 PM
gang wars? l33t-wars?
by Gremelin - 04/28/11 05:56 AM
Consolidate Forums
by diggin2deep - 04/21/11 10:02 AM
LAN Hacking Noob
by Gremelin - 03/12/11 12:42 AM
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
unreal 1
Crime 1
Ice 1
Dartur 1
Powered by UBB.threads™ PHP Forum Software 7.7.5