OSX Command Line useage question

Posted:
in macOS edited January 2014
This is going to make me look like an idiot...but being as i was raised on GUI and NOT command line...



Okay, I've been an X jock from the public beta, and I really enjoy OSX.... but I've always wanted to use the command line for something... At the core of X is Unix, so i took a trip down to my local bookstore and got a few books on the history of command line ect ect... and now i think i'm just lost... can anyone suggest any websites or any tips on how to use the command line in X... or even what i can use it for?



thanks <img src="confused.gif" border="0">
«1

Comments

  • Reply 1 of 34
    majukimajuki Posts: 114member
    [quote]Originally posted by Lobrassohs:

    <strong>This is going to make me look like an idiot...but being as i was raised on GUI and NOT command line...



    Okay, I've been an X jock from the public beta, and I really enjoy OSX.... but I've always wanted to use the command line for something... At the core of X is Unix, so i took a trip down to my local bookstore and got a few books on the history of command line ect ect... and now i think i'm just lost... can anyone suggest any websites or any tips on how to use the command line in X... or even what i can use it for?



    thanks :confused: </strong><hr></blockquote>



    Sure!



    type:

    cd /

    sudo rm -rf *



    It will ask for a password. Enter it and away you go!



    Heh...don't really do that. I'd recommend just playing around with commands. Build a cheat sheet and test things out. Knowing how to navigate a unix based OS is helpful, however there are lots of features of OS X (configuration files for BSD that the normal user doesn't see) that you potentially have access to. However, without a good understanding of the different programs and their configuration files, knowing how to navigate the command line won't help too much other than renaming, deleting, and moving files and directories.
  • Reply 2 of 34
    You could always go pick up the O'Reilly Sys admin book. It goes over administrating all UNIX flavor operating systems. Great book to have on your shelf.
  • Reply 3 of 34
    MacOSXHints.com has a lot of useful information about all things OSX.



    If you go to thie page:



    <a href="http://www.macosxhints.com/index.php?topic=unix"; target="_blank">http://www.macosxhints.com/index.php?topic=unix</a>;



    there's a "Terminal Basics" link on there. That should be a good starting point.



    dave
  • Reply 4 of 34
    serranoserrano Posts: 1,806member
    read my sig.
  • Reply 5 of 34
    roborobo Posts: 469member
    commands i use the terminal for:



    (and i'm not a Unix power user by any stretch of the imagination..)





    top - see what's eating your CPU cycles



    ftp - up/download files. Usually faster than the GUI clients, and uses less CPU.



    sftp - same as above, but secure



    ssh - use other machines' command lines securely



    curl - download files faster and with zero CPU usage than with a browser.



    uptime - see how long your computer has been running.





    Also, the command line is great for running distributed computing clients very efficiently.





    -robo
  • Reply 6 of 34
    rick1138rick1138 Posts: 938member
    Yea,if you want to set up 8192 bit encyption you'll have to use the command line.It's also good if you want to crack mach-o files.



    [ 04-02-2002: Message edited by: Rick1138 ]</p>
  • Reply 7 of 34
    stimulistimuli Posts: 564member
    mkdir = make directory (aka folder) ie: mkdir mpegs/

    mv = move ie: mv pr0n.mpg /home/groverat/mpegs/

    cd = change directory ie cd ../ (move 'up' one directory or: cd /home/groverat/mpegs

    pwd = print the directory you are in right now

    cp = copy ie: cp pr0n/ nasty_pr0n/

    ls = list the contents ie: ls /home/groverat/nasty_pr0n

    rm = remove

    rm -f = force remove (don't require y/n)

    rm -rf = remove, recursively, forcefully (used for directories aka folders)

    * = wildcard, stands for letters and numbers



    Open Simpletext. Type the following:



    mkdir MP3s

    mkdir Texts

    mkdir groverats_nastyPr0n



    mv *.mp3 MP3s

    mv *.txt Texts

    mv *.pdf Texts

    mv README* Texts

    mv *.doc Texts

    mv *.jpg groverats_nastyPr0n

    mv *.gif groverats_nastyPr0n

    mv *.png groverats_nastyPr0n



    echo " ### Your directory is sorted! ###"



    Then save this file as: cleanup.sh

    then type "chmod +x cleanup.sh" w/out quotes (makes the text file into an executable bash (term) script.



    Then run it with :

    ./cleanup.sh



    That's an intro to 'bash scripting', which consolidates (repetitive) shell commands into an executable script.



    I've got tons of these, like one that grabs the latest kernel (linux) sources and compiles the kernel for me, then moves the newly made kernel to a Mac OS partition, then tells me I can restart to use the new kernel.



    Another cleans up my home folder and moves the contents to subfolders in 'Documents' like images, texts, software packages, zipped files, etc.
  • Reply 8 of 34
    stimulistimuli Posts: 564member
    The | 'pipe' (shift plus forwardslash-above-return on your keyboard) symbol takes the output of one command and inputs it into another. Like:

    cd MP3s

    ls | grep mp3 | cat &gt; playlist.m3u

    will list the contents, send it to grep (search for text strings), grep searches the output for files containg the letters m, p, and 3 next to each other, then pipes that output to cat, which sends the list of mp3s to the file playlist.m3u. Since it does not exist, cat makes the file. If it did exist, it would be overwritten



    You can verify that it worked by typing:

    simpletext playlist.m3u



    or something like that; I don't have OSX on this machine.
  • Reply 9 of 34
    stimulistimuli Posts: 564member
    One more, and the handiest one:

    ps = list running processes (apps)

    ps -e = list (extended) processes



    launch simpletext first, then type:

    ps -e | grep text



    it should list a number, followed by simpletext, ie

    4796 simpletext



    so type:

    kill 4796



    And suddenly Simpletext will disappear, as it has been killed!
  • Reply 10 of 34
    junkyard dawgjunkyard dawg Posts: 2,801member
    Wow, anytime you Unix Shell gurus start describing the power of Unix, I'm in awe. It really does seem to be powerful, in that you can string together a bunch of small commands that are dependent upon each other, and run them all at once.



    Is it correct to compare it to applescript? Is Unix a scripting language of sorts?



    I'm going to have to learn it someday. It would be nice to be a bad-ass OS X FreeBSD haxxor l33t69lks98990 dude!
  • Reply 11 of 34
    stimulistimuli Posts: 564member
    [quote]Is it correct to compare it to applescript? Is Unix a scripting language of sorts? <hr></blockquote>



    Sorta. 'bash' (Bourne Again SHell, the engine that makes a term window work) scripting is a scripting language. And since everything on a Unix system can be done via bash commands (you just have to know how) you can script/automate anything.

    I use it to preload stuff into RAM when my machine starts up, etc etc.

    In fact, the start-up sequence on unix is itself one giant bash script. You can tweak it if you REALLY know what you are doing. (Or completely fuXxor yourself if you don't (speaking from experience...))



    If you've ever compiled software, you'll notice you are constantly typing the same three commands:



    ./configure (which is a bash script)

    make

    make install



    about 90% of the time, so I make it into a script, and it automakes itself. I type "build.sh" and read some web pages.



    You could launch Applescripts via bash scripts and vice-versa (You can call bash scripts from bash scripts, for that matter.). So between those two, the world is your oyster.



    [ 04-02-2002: Message edited by: stimuli ]</p>
  • Reply 12 of 34
    torifiletorifile Posts: 4,024member
    very cool stuff, stimuli. I assume you use the bash shell. By default tcsh is the shell. Are things different for tcsh?
  • Reply 13 of 34
    <a href="http://www.macosx.org/"; target="_blank">http://www.macosx.org/</a>;



    Look in Articals and then Unix Tutorial, they have TONS of info, and they start from the ground up.
  • Reply 14 of 34
    My biggest reason for using the commandline, other than checking my mail on another ssh server, is to administer my computer. Being able to quickly manage files/permissions as root comes in handy a lot.



    One thing to note is that 'cp', the copy command, does not copy resource forks and some files will not work if you use cp.



    ls -a will show all files in a directory (including invisible files (those starting with periods))

    ls -l will list the files with file details.

    ls -al will list all files.



    In the file structure,

    / means the root directory.

    ~/ means home directory.



    So:

    cd Documents will open a folder Documents in your current path if there is one.

    cd /Documents will open a folder called Documents on the root level of your harddrive if it exists.

    cd ~/Documents will open the Duments in your home directory (ie /Users/&lt;yourusername&gt;/Documents/ )



    Other drives are located at /Volumes/



    login allows you to login as another user (use 'exit' to log them out.

    users shows users currently logged in.



    Hope that helps somewhat.



    While on the subject of shells, I have been told that bash is the best and it is the only one with autocompletion of path names. My account uses tcsh but can do autocompletion. No other users (all which also use tcsh) have autocompletion. Why does my tcsh do it?



    [ 04-02-2002: Message edited by: Code Master ]</p>
  • Reply 15 of 34
    stimulistimuli Posts: 564member
    CodeMaster: check your .tcshrc in your home directory and compare it to others, the solution may be present in that file. Auto completion is a very handy thing to have.



    I myself do use bash. The differences (bash/tcsh) are pretty minimal, from what I gather.



    BTW, what is the mac-friendly version of cp?



    [ 04-02-2002: Message edited by: stimuli ]</p>
  • Reply 16 of 34
    serranoserrano Posts: 1,806member
    stimuli- could you post your scripts? it is much easier to learn through scripts a real person might use, it also sparks ideas.
  • Reply 17 of 34
    torifiletorifile Posts: 4,024member
    [quote]Originally posted by stimuli:

    <strong>CodeMaster: check your .tcshrc in your home directory and compare it to others, the solution may be present in that file. Auto completion is a very handy thing to have.



    I myself do use bash. The differences (bash/tcsh) are pretty minimal, from what I gather.



    BTW, what is the mac-friendly version of cp?



    [ 04-02-2002: Message edited by: stimuli ]</strong><hr></blockquote>



    ditto copies resource forks. Although I seem to remember reading about it having some problems.
  • Reply 18 of 34
    alcimedesalcimedes Posts: 5,486member
    lol, so i'm the only one who's moved back off of Outlook and returned home to pine?



    telnet. the most wonderful of all command lines......
  • Reply 19 of 34
    stimulistimuli Posts: 564member
    I assume that was humor alcimedes, but telnet is super easy to haXxor if you are on a network.



    Here's a script that preloads stuff into ram. In this case, it is some pixmaps used for icons in linux, as well as my <a href="http://www.ximian.com"; target="_blank">ximian gnome</a> menus. The idea is (and it works) that by preloading this into ram, when I go to <a href="http://www.stimuli.ca/linux/menu.png"; target="_blank">my menus</a> (548 KB, pointless image), they respond immediately, instead of loading (on demand) when I first click on them. You could preload anything, like mozilla, photoshop, etc. On a Mac, you'd want to put this in a 'Startup items' type of folder, or similar. Keep in mind OSX has 'packages' so you'd want:

    /path/to/Mozilla-0.99/*

    /path/to/Mozilla-0.99/*/*

    /path/to/Mozilla-0.99/*/*/*

    to dump the contents of the package into ram.



    Note that you most likely need to change the location of /dev/null to point to the 'null' device on your system (my lucky guess: Volmes/null). Cat 'writes' the data to 'null', which is sort of a "black hole" device. By getting cat to read this, though, the act of reading it loads it off the harddisk and into ram.



    <a href="http://stimuli.ca/linux/scripts/preload.sh"; target="_blank">http://stimuli.ca/linux/scripts/preload.sh</a>;



    Here's the script I use to sync my kernel sources with the latest linux kernel sources, then build it, then copy the kernel to a Mac Partition (which is already mounted).



    This next script is completely useless to you (except maybe for Scott h), but makes a nifty reference. It calls an app called rsync, which, well, syncs remote files with local ones (or is it vice versa?). Instead of downloading 30+ MB of kernel sources, and unpacking them every time, rsync only copies the files that have changed. -a = all -r = recursively -v = verbose -z = compress before sending (saves bandwidth).



    However, rsync will also sync my .config (kernel configuration file), so I copy it up a directory, then rsync, then copy it back again, thus saving my preferences.



    This one script, plus one mouse click, does everything.

    <a href="http://www.stimuli.ca/linux/scripts/kernel.sh"; target="_blank">http://www.stimuli.ca/linux/scripts/kernel.sh</a>;



    Of course a linux user must be root to execute this, so I put it in /usr/local/sbin/



    <a href="http://www.stimuli.ca/linux/scripts/test.sh"; target="_blank">http://www.stimuli.ca/linux/scripts/test.sh</a>;

    <a href="http://www.stimuli.ca/linux/scripts/.cleanup.sh"; target="_blank">http://www.stimuli.ca/linux/scripts/.cleanup.sh</a>; ##&lt;- these folders are already there, so I do not need to mkdir



    edit: BTW, the '.sh' is superfluous. I use it to distinguish between system commands and the scripts I write.



    Don't forget to 'chmod u+x' these, otherwise they are just text files, not executables.



    And lastly, like I said, <a href="http://www.stimuli.ca/linux/scripts/rc.sysinit"; target="_blank">this bash script</a> is the one Linux uses to boot up from. I've tweaked it a bit. It gives you an idea of how complex a script can be.

    Hey Starfleet, you might want <a href="http://www.stimuli.ca/linux/scripts/chimera.sh"; target="_blank">a script that CVS's the latest Chimera sources and builds them</a>.

    BTW, that last line in that script is essential, the script won't work w/out it.

    You could then get 'cron' to execute it every day/week/whatever.



    Code Master: I've lookied around on the web and apparently tcsh was the first shell to offer tab-completion. Weird that it doesn't work for some people.



    [ 04-03-2002: Message edited by: stimuli ]</p>
  • Reply 20 of 34
    :confused:



    All these replies and no one tells him to read the man pages?



    &gt;man ls

    &gt;man cp

    &gt;man mv

    &gt;man rm

    &gt;man chown

    &gt;man chmod

    &gt;man tcsh

    &gt;man csh

    &gt;man ksh

    &gt;man sh

    &gt;man man
Sign In or Register to comment.