Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Command line tips & tricks

24

Comments

  • Closed Accounts Posts: 18,969 ✭✭✭✭syklops


    Khannie wrote: »
    Handy. FYI - find has an exec option, so:

    find <stuff> -exec cp {} <destination> \;

    I regularly use it to grep stuff in a large set of files / directory tree:

    find <stuff> -exec grep --with-filename <pattern> {} \;

    I was just about to post that


  • Moderators, Technology & Internet Moderators Posts: 37,485 Mod ✭✭✭✭Khannie


    cd /home/somedir
    python -m SimpleHTTPServer

    presto! "somedir" is served up on port 8000. Very handy way of moving files between machines where you don't want to give (or aren't arsed setting up) SSH login for example.


  • Closed Accounts Posts: 18,969 ✭✭✭✭syklops


    Khannie wrote: »
    cd /home/somedir
    python -m SimpleHTTPServer

    presto! "somedir" is served up on port 8000. Very handy way of moving files between machines where you don't want to give (or aren't arsed setting up) SSH login for example.

    I regularly use that. Its dead handy.


  • Registered Users Posts: 10 The_Old_Grey Whistle_Thief


    You can use Ctrl-l instead of clear to clear the screen.
    Probably my most used command. I just can't seem to work on a full screen.


  • Moderators, Technology & Internet Moderators Posts: 37,485 Mod ✭✭✭✭Khannie


    Putting a space at the start of a command means it doesn't get added to bash history.

    " mplayer omgfilthyporn.mkv" :pac:

    or more usefully:

    " sudo mount hidden_encrypted_volume" (note, sudo'd commands go into syslog by default, but you can disable that too on a per-command basis).


  • Advertisement
  • Closed Accounts Posts: 3,981 ✭✭✭[-0-]


    Khannie wrote: »
    Putting a space at the start of a command means it doesn't get added to bash history.

    " mplayer omgfilthyporn.mkv" :pac:

    or more usefully:

    " sudo mount hidden_encrypted_volume" (note, sudo'd commands go into syslog by default, but you can disable that too on a per-command basis).

    Love this!


  • Banned (with Prison Access) Posts: 1,151 ✭✭✭rovoagho


    This thread is like porn for nerds, thanks to all the contributors. I just have to make myself read it once a week now so I'll remember it all!


  • Hosted Moderators Posts: 3,331 ✭✭✭Splinter


    only installed Mint properly at the weekend and was talking to Syklops last night and said "ah "Alt + ." is great but i can't say i can see myself using it... needless to say i have very much eaten my own hat. fantastic thread folks :)


  • Closed Accounts Posts: 18,969 ✭✭✭✭syklops


    Splinter wrote: »
    only installed Mint properly at the weekend and was talking to Syklops last night and said "ah "Alt + ." is great but i can't say i can see myself using it... needless to say i have very much eaten my own hat. fantastic thread folks :)

    Yeah you didn't sound very interested in it last night, but maybe it was how I was explaining it. You have to do it to under stand. I find it great for networking tools. So you ping 192.168.253.1, and then you traceroute [alt + .] and then you nmap [alt + .] and then you nc -vv [alt + .] 22.


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    This opens nautilus with current directory (kinda obvious...)
    nautilus .
    
    same can be used for image viewer eog:
    eog .
    
    and the amazing command for removing duplicate files - fdupes
    most common usage (run in current dir, dive into sub dirs and ask what files to preserve if duplicates are found):
    fdupes -R -d .
    


  • Advertisement
  • Closed Accounts Posts: 3,981 ✭✭✭[-0-]


    Cross post from Development.

    Vundle
    Syntastic
    my .vimrc:
    syntax on
    se nu
    set autoindent
    set cindent
    
    set rtp+=~/.vim/bundle/vundle/
    call vundle#rc()
    
    " let Vundle manage Vundle
    " required!
    Bundle 'gmarik/vundle'
    
    
    Bundle 'scrooloose/syntastic'
    let g:syntastic_enable_signs=1
    let g:syntastic_auto_loc_list=1
    let g:syntastic_mode_map = { 'mode': 'active', 'active_filetypes': ['c'], 'pa
    ssive_filetypes': ['html', 'css', 'slim'] }
    
    Bundle 'scrooloose/nerdtree'
    Bundle 'scrooloose/nerdcommenter'
    nmap <leader># :call NERDComment(0, "invert")<cr>
    vmap <leader># :call NERDComment(0, "invert")<cr>
    Bundle 'majutsushi/tagbar'
    Bundle 'gregsexton/gitv'
    Bundle 'sjl/splice.vim'
    Bundle 'tpope/vim-fugitive'
    

    See the attached image for syntastic in action


  • Registered Users Posts: 28 adrianm68


    These are great, thanks for posting. You all probably know this one :

    sudo !!

    Runs the previous command as super user in case to you forgot.


  • Banned (with Prison Access) Posts: 1,151 ✭✭✭rovoagho


    See the very first post. :)


  • Registered Users Posts: 28 adrianm68


    rovoagho wrote: »
    See the very first post. :)

    Omg! Have I really become one of 'those' people. OK so I got caught out. I admit to having not read the thread before posting how much I liked it. People are strange. Especially me!

    Apologies if I woke anyone up.

    Zzzzz zzzzz


    Adrian


  • Registered Users Posts: 6,392 ✭✭✭AnCatDubh


    Somewhat related is an account on twitter - https://twitter.com/climagic

    on the go since 2009 and with about 7k tweets, it should keep your interest going on, and on, and on, and on, and......................

    :)


  • Registered Users Posts: 569 ✭✭✭hooplah


    Speaking of resources, if you haven't seen it already http://explainshell.com is really handy. Especially for when you're following tutorials or problem solutions from something like stackexchange


  • Moderators, Technology & Internet Moderators Posts: 37,485 Mod ✭✭✭✭Khannie


    For ubuntu, if you need to build something from source, this command installs all build dependencies prior to the build:
    aptitude build-dep <package>
    

    Winner, winner, chicken dinner.


  • Registered Users Posts: 116 ✭✭partyboy690


    The single most used command on my job

    find . -iname "*.cpp" -exec grep -Hn "Something in code I need to find" {} \;

    Ctrl+R and Ctrl+L are vital as well, couldn't get on without them.

    Another really handy one is this, we use it extensively at work to kill jobs on remote machines through jenkins

    kill -9 `ps -e | grep <Whatever the name of the job is> | cut -d' ' -f1`


  • Registered Users Posts: 1,089 ✭✭✭KAGY



    Another really handy one is this, we use it extensively at work to kill jobs


    kill -9 `ps -e | grep <Whatever the name of the job is> | cut -d' ' -f1`

    correct me if I'm wrong but would killall processname do the same job


  • Registered Users Posts: 116 ✭✭partyboy690


    KAGY wrote: »
    correct me if I'm wrong but would killall processname do the same job
    You're correct it would but this command is for specialised scripts we run and it doesn't have a nice processname like firefox or something like that, so we need to just know the name of the properties file and we can kill the jobs that way. Our Jenkins setup is very convoluted :D we have to implement hacks just to get things working, I'm the guy who maintains it and I'm slowly improving it over time to make it so we don't need ridiculous commands like that.

    EDIT: Will say the setup was there before I joined otherwise it'd be much better ;)


  • Advertisement
  • Registered Users Posts: 1,089 ✭✭✭KAGY


    I had edited my post to include this, but I'll repost it here to keep the flow of conversation:-

    btw you could add those string of commands into .bashrc as a function.
    function mykill () {kill -9 `ps -e | grep "$1" | cut -d' ' -f1`}


  • Registered Users Posts: 116 ✭✭partyboy690


    KAGY wrote: »
    I had edited my post to include this, but I'll repost it here to keep the flow of conversation:-

    btw you could add those string of commands into .bashrc as a function.
    function mykill () {kill -9 `ps -e | grep "$1" | cut -d' ' -f1`}
    Yeah I could do that6, doesn't make too much of a difference because this command is run adhoc as a job on Jenkins.


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    Those are not typical command line tips, but I hope they are close enough to fit into this thread.

    In vim:
    :make - This will run the regular old make in the command line for you.
    :copen - Opens the quickfix window, to show the results of the compilation
    :cw[indow] - Opens the quickfix window only if there is an error.
    :cn - Goto the next error in source code.
    :cp - Goto the previous error in source code.
    :cfirst - Goto the first error in source code.
    :clast - Goto the last error in source code.

    P.S. All credit goes to the author of [URL="In vim: :make - This will run the regular old make in the command line for you. :copen - Opens the quickfix window, to show the results of the compilation. Opens the window even if there are no errors in compilation. :cw[indow] - Opens the quickfix window only if there is an error. If quickfix window is open and there are now errors, the window is closed. :cn - Goto the next error in source code. :cp - Goto the previous error in source code. :cfirst - Goto the first error in source code. :clast - Goto the last error in source code. how come that I did not know those earlier?? P.S. All credit goes to the author of this blog"]this blog[/URL]


  • Closed Accounts Posts: 1,004 ✭✭✭Recondite49


    Generate a random number between X and 1 (in this case 10) drawing directly from the pool of random data.

    echo "$(od -An -N4 -tu4 /dev/random) % 10 + 1" | bc

    You can check available levels of entropy in your system as follows:

    cat /proc/sys/kernel/random/entropy_avail

    Be advised that checking available levels of entropy in itself uses up entropy.

    If you need lots of random numbers, a personal favourite program of mine is randomsound. It uses white noise from your sound card and pipes it straight into /dev/random.

    This comes in very handy when trying to generate gpg/SSL keys.


  • Closed Accounts Posts: 1,004 ✭✭✭Recondite49


    Another nugget I discovered the other day.

    A friend of mine had a folder with over one million jpgs inside it. He wanted to know if there was a terminal command which would allow for automatic search and deletion of all images below a certain size (in this case 250kb).

    After some judicious googling I saw that this can be done in one line:

    find . -name \*.jpg -size -250k -exec rm {} \

    This will take some time but at least it's simple.


  • Closed Accounts Posts: 27,857 ✭✭✭✭Dave!


    jeans-out-of-dryer-tuco-tight-tight-tight-breaking-bad.gif


  • Closed Accounts Posts: 18,969 ✭✭✭✭syklops


    Dave! wrote: »
    jeans-out-of-dryer-tuco-tight-tight-tight-breaking-bad.gif

    Anyone else baffled?


  • Moderators, Technology & Internet Moderators Posts: 37,485 Mod ✭✭✭✭Khannie


    It means "great". Quoting pictures! I'm surprised at you. :P


  • Closed Accounts Posts: 18,969 ✭✭✭✭syklops


    Khannie wrote: »
    It means "great".

    News to me.
    Quoting pictures! I'm surprised at you. :P

    Well if I didnt quote the picture, how would anyone know what I was baffled about?


  • Advertisement
  • Moderators, Technology & Internet Moderators Posts: 37,485 Mod ✭✭✭✭Khannie


    syklops wrote: »
    News to me.

    Have you not seen Breaking Bad??? :eek:


Advertisement