Linux (49)


running a shell from vi

  • August 28, 2012
  • vi

sometimes you are editing a file and need to quickly do something back on the command line. the usual practice would be to save the file, exit to the shell, do your stuff, then reopen the file again… instead, when in vi, do :sh this will send you back to your command line, where you […]

Read more...



oops, i edited and i’m not root

  • August 28, 2012
  • vi

the amount of times i have been editing away at a file in vi and gone to save it only to realise i’m not root… if my edits were all in one block, i’d usually end up copying the text with my mouse, closing the file, su to root, open it up, paste, zzz…. so. […]

Read more...



finding hard coded document roots

  • August 28, 2012
  • Linux

currently migrating sites across to new servers. some of the older sites have hard coded paths in their configuration files (rubbish i know), so to find out which files, we’ll use find. cd into /var/www/vhosts and run the following find command: [code] cd /var/www/vhosts find . -name ‘*.php’ -exec grep -i -H ‘/var/www/vhosts’ {} \; […]

Read more...



bash clever built-in expanders

some helpful shortcuts when on the bash command line: !! repeats the last command !$ returns the last argument of the previous command !^ returns the first argument of the previous command !* is all of the arguments from the previous command

Read more...



curl

  • August 27, 2012
  • Linux

curl is powerful. simply doing [code]curl http://url[/code] will return the contents of the page. sending post data [code]curl -d id=2&this=that&c=1&var=x http://url[/code] get the headers, -I does gets headers, -v is extra detail, being verbose. [code] curl -Iv http://url[/code] get a page and save it locally [code]curl http://url > file[/code] or use -o, i put it […]

Read more...



sending emails with telnet

How to send emails with telnet. Sending emails with telnet is very easy. Open telnet and connect to the server, specifying the port too: [code]telnet mailserver.com 25[/code] if successfully connected, you will be greeted with something like: [code] telnet mail.stus.co 25 Trying 46.32.231.1… Connected to mail.stus.co. Escape character is ‘^]’. 220 stus.co ESMTP Postfix [/code] […]

Read more...



reading emails with telnet

  • August 27, 2012
  • Linux

How to read emails with telnet. Reading emails with telnet is just as easy as sending emails with telnet. So we will be logging into a pop3 box using telnet start telnet, by typing telnet. connect to the mailserver of choice: [code]open mail.server.com 110[/code] so you should see: [code] telnet> open mail.stus.co 110 Trying 46.32.231.1… […]

Read more...



splitting large files

  • August 26, 2012
  • Linux

to split a large file into chunks… [code]split –bytes=2m bigfile.tar bit_[/code] and to join chunks back together again: [code]cat bit_* >> newbigfile[/code]

Read more...



archiving: zip, tar

  • August 26, 2012
  • Linux

tar to compress a directory [code]tar zcvf thetar.tar dir/[/code] uncompress a tar [code]tar zxvf thetar.tar[/code] if you need to tar up loads of files, and find yourself getting ‘argument list too long’, then use this: [code]find -iname ‘*.JPG’ > imageList tar zcvf feedImages.tar –files-from imageList[/code] excluding files or directories when tar-ing up a directory, sometimes […]

Read more...