Thursday, August 04, 2011

Linux Command Line Quick Intro

hehe... Quick.

So a friend of mine, let’s call him Aaron, it’s a good name. Anyways... Aaron is fairly familiar with Linux, but isn't overly friendly with the command line. As he puts it, he likes "pretty things" and we all have to admit there isn't much pretty about the terminal. So I compiled my entire bash history, sorted and wrote/stole some explanations of how I use terminal and regularly used command line programs. Hopefully this helps somebody, maybe you. It helped me at least as an exercise in documentation.
So here goes:

/var/log/messages is your friend. This is where a lot of the daemons log to. I often use this in conjunction with tail and/or grep.

Tab completion is your friend. Start typing a command and then press tab once to complete it and tab twice to list all possible completions, works on directories, commands and aliases

#output the results of a command to a file, called piping. In this case it is ls
ls > output.txt
ls >> output.txt // this appends the output of ls to the file output.txt

#execute one command based on the output of the other, specifically standard out, this is apparently called concurrency. The following will list all running processes in full detail and find only the lines with “named” on it.
ps -ef | grep named

#execute one command after another
cd /root; ls

#find out what version of Linux you have
uname -a && cat /etc/*release

#move files from one host to another over ssh, must use full filepath from /
scp root@172.16.1.2:/root/.bashrc /root/.bashrc

# request new ip using dhcp
sudo dhclient

#restart networking has the same effect of requesting new ip.
/etc/init.d/network restart

# redhat based, ie redhat, fedora, centos, scientific
yum update
yum search
yum install
yum info
yum remove

#debian based, ie debian, ubuntu, mint
apt-get update
apt-cache search
apt-get install

#port scan remote host, not overly abusive
sudo nmap -T2 -v -A -PN

# Find files
# where /etc is the directory to search can also be . for the current directory and all sup
# directories and search by name of file in this case *.cpp
find /etc -type f -name “*.cpp” -print | sort -u

#find text in a file in filesystem
find . | xargs grep "text"

# un gzip and un-tar, works on *.tar.gz and also *.tgz
tar -zxvf file.tar.gz

#edit /user/donald/.bashrc to modify coloring of terminal and regularly used aliases
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\] $ '

#the syntax for PS1 varies this above works in Fedora 13
export SVN_EDITOR="/bin/nano"

alias ll='ls -l --color=auto --group-directories-first' // I use ll ALL the time

#and if I find myself constantly changing to one directory I’ll often set an alias of
alias cdproject=”cd /home/aaron/Documents

#install ssh server
apt-get install openssh-server

#install Webmin on Ubuntu
sudo su
echo "deb http://download.webmin.com/download/repository sarge contrib" >> /etc/apt/sources.list
echo "deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib">> /etc/apt/sources.list
wget http://www.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc
apt-get update
apt-get install webmin

#install LAMP on Ubuntu
apt-get install mysql-server mysql-client
apt-get install apache2
apt-get install php5 libapache2-mod-php5
apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
/etc/init.d/apache2 restart
echo -e "" > /var/www/info.php

Command My Description
alias print out all aliases currently in use, these are typically stored in your home directory in a file called .bashrc
cat .viminfo concatenate the output of the foo.txt to stdout or in otherwords print out the file
chmod+x install_webmin.sh change the mode of the file to be executable to all owners, groups and world
chmod 740 www same except explicitly defining the mode, b
Owner Group World
R W X R W X R W X
4 2 1 4 2 1 4 2 1
7 4 0
RWX R none

chown root:wheel manage.py Change the owner to root and the group to wheel of the file manage.py
chown root:root * -R Change the owner and group to root of all files and folders in the current directory and do it to all subfolders and files recursively
clear clear all text from the current terminal
cp
copies file or directories from source to destination, if wanting to recursively do directories, be sure to include -R
dd if=/dev/cdrom of=disc6.iso; eject create an iso of the disc in the drive and store it as disc6 in the current directory and eject aftwards
df display current disc utilization stat. Add -a for all discs and -h for human readable sizes
diff tmp.txt tmp2.txt display the difference between the two files specified
dig soecs.ku.edu dig up some dns info about the given server or domain
echo $PS1 print the contents of the given variable
echo d68d6c2e04c998>vmware.txt replace all contents of the given filename with the content specified, if filename doesn't exist, attempt to create the file
fg resume the last bg process
find . -size >1G find all files in the current directory larger than 1GB
find . -user jlfugett -print find all files in the current directory whose owner is jlfugett
find / -name *.sh -print find all files and where the extension .sh
find / -name *ldap* -ctime -0.04 find all files and folders where ldap appears in the filename created within the last hour, 0.04 is approx 1/24
find /etc -name klogd -print find all files and folders in /etc where the name of the file begins with klogd
g++ -c main.cpp compile main.cpp
gksudo wireshark run wireshark graphically as root, assuming you have gksudo installed
grep g++ -R * find all instances of the phrase "g++" in all files and subfolders
grep try *.py find all istances of the phrrase "try" in all files with .py extension in the current directory, do not recurse into subdirectories
groups <user> show all groups a user is a member of
gunzip totalvalidatorbasic.tar.gz just unzip the file total…tar.gzz
gzip totalvalidatorbasic.tar gzip the .tar file
hardinfo ubuntu: brings up the hardware info gui applet thingy
history print out all previously used terminal commands
history | grep nestat find all entries of the command netstat in history
hostname print the hostname
ifconfig <interface> print the current configuration of the specified network interface. If none is specified, all active interfaces will be printed
ifdown <interface> take the specified interface down
ifup <interface> bring the specified interface up
ip addr print the current ip configuration of all interfaces
iptables -L -n Print all current chains and rules in iptables
kill 1477 end the process given by the specified process id (PID)
less /etc/apache2/httpd.conf print the given file to the screen in a scrollable format. This is often used concurrently with another command i.e. "ll -a | less"
ln -s <source> <destination> create a symlink from the source file to the destination. Analagous to .lnk files in windows
locate PyQt4 search the locate database for files
lsof list open files
lsof -i tcp:80 list open files in use by port 80
man <command> get the manual or man page for the command specified, note program man must be installed and the command must have the man page installed, luckily both of these are typically done by default
md5sum <file> display the md5sum of a file specified
mkdir /home/donald make a directory called donald in /home
mv <source> <destination> move the file <source> to <destination>. I often use this instead of rename, because the end result is the same and mv is a lot less letters than rename
mysql -h localhost mysql client: connect to host specified
nano test.txt Nano is a basic text editor, open the specified file, if no file is specified, opens an empty file that can be saved on exit
netstat netstat is very similar to its windows counterpart,it shows all tcp/udp connections in or out of the host.
netstat -tan | grep LISTEN show ALL TCP connections in NUMERIC form, but only display the ones in listen state. Alternatively, use netstat -tanl
nslookup mail.google.com analogous to nslookup in windows, the internet recommends dig over nslookup
ntpdate -b <time server> set the time on the host to that specified by the given time server
ping time.ku.edu ICMP echo to host specified. I typically set an alias in my .bashrc ping="ping -c 5" because this will perform a never ending ping
ps --help get help for the command ps, the --help is useful for many commands
ps -ef print ALL(-e) running processes in FULL(-f) detail
ps -ef | grep wireshark same as above, except only show the lines with "wireshark" in them
pwd Print Working Directory, show what directory you're in
reboot reboot the computer, must be root or sudo
rm -rf Documents Forcibly(-f) and recursively(-r) remove the folder Documents and all of its subfiles and subfolders
rmdir Documents remove the empty directory Documents
route print the routing table
scp <username@host>:<file to send> <file to receive> Secure Copy, transfer a file over ssh, file paths must be finitely defined. i.e. scp root@172.16.1.2:/root/.bashrc /root/.bashrc
service most often used to start, stop or restart a service. Typically executing scripts in /etc/init.d/
service --status-all print the up/down status of all services installed
service networking restart Ubuntu restart networking
shred removes a file and overwrites the data.
sl Choo Choo!
smbclient -L -U Administrator -W Home.local server1.home.local command line Samba client. In this context, used to list shares of the server "server1.home.local" with the username "Administrator" of the domain/workgroup "home.local"
source ~/.bashrc After editing you're .bashrc file, run this to update to the most current version
sudo ssh root@firewall.home.local -L 2222:172.16.1.2:22 Secure Shell: the -L requires root permissions, hence the sudo. In this scenario, I'm shelling into a remote router firewall.home.local. And from that firewall, I am accessing ssh on the remote server 172.16.1.2 and redirecting that to my local box on port 2222, thus creating a tunnel.
startx if X is installed at a terminal, start it.
stat <filename> print out statistics about a file, permissions, dates, owners, groups, etc
su <username> assume the role of another user, if username is not specified, become root
tail -f -n 25 /var/log/messages print just the tail of the file specified, in this case -f follows the file. And -n 25 specifies print out the last 25 lines
tar -zxvf file.tar.gz un gzip and un-tar, works on *.tar.gz and also *.tgz
telnet <host> <port> Telnet into the host and port specified, not that is a space seperating the two. Since telnet has been effectively replaced by ssh, this is most often used to determine if a given service is up such as smtp, vpn, or imap
top shows the top running processes
tracepath <hostname> analogous to traceroute in windows
uname -a print out the current kernel version
uname -a && cat /etc/*release print out the current kernel version and distibution details
users prints out the users currently logged in.
vim tmp2.txt VIM!
wget https://dl-ssl.google.com/linux/linux_signing_key.pub web get, requests and downloads the file specified
whereis sysinfo locate the binary source and manual page files for a command
who prints out the users currently logged in.
whoami prints out who you are logged in, props to Sam Flynn in Tron:Legacy for using this
whois waterone.org get whois info for the domain specified, I believe this queries the root servers
wireshark Packet sniffer, very useful if you specify narrow filters, overwhelming if you don't

Friday, July 29, 2011

By Jove I've Got It! 7-zip saves the day.

So this past week I've been working on data recovery. This computer that I've been working on had such a catastrophic problem that you couldn't even boot into safe mode. Most searches for the errors I found pointed to nuke the drive and start over. So I took an image of the drive using Acronis True Image Western Digital Edition that comes bundled with new WD hard drives as it was the only tool I had installed that would create an image. Worked great, the backup was fast and complete. So I nuked the hard drive and reinstalled Windows. Whoo!

So I have a working computer now, problem solved. Now to go the extra mile and perform that data recovery. Should be simple right? All I have to do is mount the image using Acronis and copy the files over the network right? WRONG! The files were marked as private.

But no matter, I'm logged in as a Windows Administrator I have all rights to all things in my computer right? WRONG. Apparently there is a known disconnect with .tib files and permission settings that prevent anyone from taking ownership over those files.

But no matter, I've got VMware Workstation installed and it can convert from .tib files right? WRONG. At least in my experience, but maybe if if those .tib files were created using Acronis' server grade products, but not with the lowly Western Digital Edition. VMware gave a lovely error with this: "The source parameters are incorrect."

But no matter, I've got an ESXi distribution and VMware converter at work, that should be able to handle the conversion to VMware right? WRONG. see above for the same error message.

But no matter, Acronis True Image Home available for free 30 day trial can convert to VMware right? WRONG. Yeah it just flat out didn't do it.

So you're probably wondering how I was able to finally do it. Using the 30 day trial of Acronis True Image Home, I converted the image to a Windows Image (.vhd) then using 7-zip of all tools. I was able to open the image, see partitions stored in .img files, open those up again with 7-zip and extract the files. WHOO!!!

Now if that's not a kludge, I don't know what is.

Thursday, March 11, 2010

My Sprint Blackberry and other random tidbits

Man I love my BB, it got me through this LOVELY southwest flight with its music player and games. I will say this if southwest.com hadn't been so lame and let me check in for our flight earlier like I wanted, I would probably be sitting next to my wife, that would be a lot better. We're flying out for my sister in laws wedding this weekend, she's getting married in the LA temple. I've never played so much Brick Breaker and Sudoku in my life. and I do have to say the media player is pretty good, much better than other phones I've used.

So I've been taking a break from learning / working on Karina's music instead I've been working on her website. I have launched it publicly yet, soon enough though. I've learned firsthand how powerful HTML & CSS in combination with JavaScript have become. I think we have a pretty sharp looking site. And a couple of HUGE shout outs for all the input and support I've gotten from Donald of DataWorks and Andy of wizardofogz.com design. I wouldn't have been able to accomplish much of anything without these guys answering every silly little question at 1am.

Posted from my Sprint BlackBerry 8530

Wednesday, September 02, 2009

I HAVE A TESTIMONY!

Well at 2am what better to do than to post a blog entry as I have been so diligently working on my linear algebra homework, okay elementary linear algebra homework.

So I read some rather disheartening news tonight, it’s probably very old in the world of news, but I just found out that Will Swenson the main actor in the infamous Mormon Cinema movie "The Singles Ward" is inactive and playing half naked in a revival production of the play "Hair" on Broadway, divorced with two children. I later found out the main actor of "God's Army" and producer/director Richard Dutcher has decided to leave the church though his wife and children will remain as members.

It’s interesting to me that in the key films in both of these men's lives, their characters have a brush with the very issue they are facing now. Swenson is inactive just as his character was in "The Singles Ward" and Dutcher has left the church just as he counseled the young missionary to avoid the filth of anti-Mormon literature in "God's Army". Just a little ironic to me, that's all. I do wish nothing but success and happiness for these men, I really do.

But I will keep this brief as I conclude with my testimony. I know that Jesus Christ lives, and I will announce this truth from the tops of the mountains! Or at least from my blog. I know that He and His Father appeared to a young farm boy in the spring of 1820 in upstate New York. I know the Church of Jesus Christ of Latter-day Saints is just what it claims to be: God's church restored in the last days by His prophet. I know that Thomas S. Monson is a prophet of God; I know he speaks intimately with our Lord and conducts the affairs of the Church according to the Lord's will. Now, I like facts, I like things that are tangible, that I can hold on to, that I can see, feel, dissect, see what makes it tick. And I know the Spirit of God confirmed to me the truthfulness of this Gospel more firmly in my heart than anything else ever has. The heavens and the earth may pass away, and science says they will, all that the Lord has promised shall be fulfilled.