UNIX question (easy)

Discussion in 'macOS' started by thenightwatch, Oct 2, 2012.

  1. thenightwatch macrumors newbie

    Sep 18, 2011
    Sorry if this is in the wrong forum. How do I delete or move individual files in any trashcan in the Terminal? It can be my user trashcan or all user trashcan directories.

    I know how to move around to different trashcans in different user folders, and on other volumes. But I don't know how to choose what to delete. I'd like to be able to see every single file that's in every single trashcan and choose which ones to keep, move or which ones to delete in one command if possible. Also, I'd like a readout of files being deleted or moved? (I partly know the command for that).

    This command takes me to a different user's folder on a different drive and shows me the contents. But, even though I can see them in my users account in the Finder and I can remove one file and then empty the trash, then put the file back in the trash, it would be great to do it in the Terminal, and save a lot of time. I didn't know if the Trash being an invisible directory required something different.

    $ cd /Volumes/volumename
    mac-pro:volumename admin$ cd ~/.Trash
    mac-pro:.Trash admin$ ls -1 | wc -l
    mac-pro:.Trash admin$ cd ..
    mac-pro:~ admin$ cd /volumename/.Trashes/503
    mac-pro:503 admin$ ls
    File 1 - File 2

    Ok, so I see the two files. How do I delete File 1 and move File 2 to my home desktop, but not touch ANYTHING else?

    Because I have lots of hard drives, I sometimes need to copy a file from another users trashcan to my desktop, while deleting the other. Btw, all the accounts on this computer are mine.

  2. ScoobyMcDoo macrumors 65816

    Nov 26, 2007
    Austin, TX
    The command rm deletes files
    The command mv moves files
    The command cp copies file.
    The command man shows the manual page for a command. E.G "man rm" will tell you all you want to know about the "rm" command.
  3. thenightwatch thread starter macrumors newbie

    Sep 18, 2011
    Thanks ScoobyMcDoo. I was hoping for a command hint, or at least part of it and I could fill in the blanks (carefully of course with research). Do I need to use "sudo" because it's multiuser? and ".."" to go to another volume?

    So, from the trash directory I'm in, I want to delete File 1 and move File 2 to my user's account's desktop that's on another volume.

    sudo rm-v File 1


    sudo mv File 2 cd ../Volumes/volumename/Users/usernameDesktop

    Is that right? I'm researching it now, but any help would be appreciated. Thanks!
  4. ScoobyMcDoo macrumors 65816

    Nov 26, 2007
    Austin, TX
    Use sudo if you are reading a file which you do not have read permissions or writing to a folder for which you do not have write permissions.

    ".." simply means one directory higher. For example if your current working directory is "/home/thenightwatch/Documents" then ".." would mean /home/thenightwatch".

    To get to another volume, you would simply use "/Volumes/VolumeName"

    Just to head one of your next questions off at the pass, spaces in filenames and folders need to be "escaped" with a backslash. For example the default HD volume name is "Macintosh HD" so if you want to access it, it is "/Volumes/Macintosh\ HD"
  5. thenightwatch thread starter macrumors newbie

    Sep 18, 2011
    Ha. Good job of predicting my thoughts. This is a bit off topic but, my main boot drive is (ridiculously) named "MacBoot SSD 256GB". I'm going to change that once I figure out how not to mess everything up. I tried changing the names of three volumes by control-clicking in the sidebar but all hell broke loose. I have my os/apps on volume 1, some of my home directory on volume 2 (iTunes, iPhoto, etc..), and volume 3 stores some files that refer back to volume 1 (MacBoot SSD 256GB) (volume 2 is a TM volume). When I changed names many items didn't know where things were (permission and pathway info did not get written in the directory and repairing permissions, of course, did not fix that). It seems, unlike System 7, that OS X needs to be told what you're about to do. I need to find a way to change the names of the three volumes and have all of the directory and permissions files correctly update too. In System 7 you could rebuild the directory. Repairing permissions is like that, but seems to not be as "smart" (I understand why). I'd like to do this right with the Terminal, especially with my home folder being on volume 2. I have yet find much info on troubleshooting with your home folder on another volume using Terminal. Still looking and thinking though. Perhaps if I change one volume name at a time, repaired permissions and restarted, then repeated..?

    So anyway...

    If you don't mind... I want Terminal to show me the actions it's taking (I want to see what's happening in real time). Should I use verbose, "-v" or is that too much and should I use a more common "show what you're doing" command? I don't know that command is.

    Also, it it possible to do both commands, trash one file, and move the other, in one large command, or do I need to do this in two steps?

    Thanks for the reminder on the backslash. I recall that but did not know it dealt with the spaces in paths. So for MacBoot SSD 256GB, would I use "/Volumes/MacBoot\ SSD \256GB" or "/Volumes/MacBoot SSD 256GB"? I did "man ls" and saw "-f" adds the backslash I believe, whicg led me to believe that option 2 was the correct syntax. I also read "man mv", and "man rm". So, I'm getting it. Thanks for that.

    Thanks for all your time and knowledge. I've bought a couple of books on UNIX commands and am reading up. They were practically giving away OS X based UNIX books at the store! Gotta get PRO at this stuff.
  6. ScoobyMcDoo macrumors 65816

    Nov 26, 2007
    Austin, TX
    I haven't changed volume names, so I really can't give you any useful advice. I thought that OSX's use of aliases rather than symlinks was supposed to help with this sort of thing, but I may be wrong.
    Each command may have a verbose command, you will have to look at the man page for the specific command you are using to see what flags are available. The only "show me what you are doing" is "set -x" which is typically used when debugging shell scripts.
    You can stack commands on one command line with either a semicolon or a double ampersand. The double ampersand will only execute the second command if the first one succeeds. So for example if I am building a program with make and want to install it only if it builds correctly I could write:
    $ make && make install
    If you find you are frequently doing the same large command with different arguments, you might consider creating an alias. You should be able to find some documentation about aliases by googling or in one of the new books you just acquired.
    Well, you can actually use both methods. The former should be used without double quotes, and the latter can be used if you encapsulate the path name within double quotes. By the way, assuming you are using the bash shell, you can use the tab key for autocompletion and it will use the correct format.

Share This Page