How to go to a specific file in Mac Terminal? - macos

I'm trying to follow a walkthrough and this is one of the steps, "go to that same folder in Terminal (if you can't do that you should probably quit now)" I'm not very familiar with Mac's Terminal, but don't feel like quitting. If it helps, I need to run a grep -r "what I'm looking for" command on the file. I really have no idea what I need to do to run that command, but the rest of the walkthrough is pretty thorough, so I know I can follow the next few steps.

You need to move to the directory where that file is stored, for this the command is cd. For example lets say the file is located in a directory names MyDir in the Desktop, the command will be
cd /Users/{YOUR_USERNAME_HERE}/Desktop/MyDir
You can run ls command here to check if the file is actually present in this directory or not

Related

File disappeared after trying to move it in terminal

Can anyone tell me where my file may have gone after this command?
The file I'm missing is stats.cpp
And what is the correct command to move it from directory prog3a to prog3c?
Thank you.
Since you did not post the actual command you used I cannot tell you what happened to the file. What I can say is that unless you used the rm command, the file is not gone. Probably got its name changed if you cannot find it or it got moved somewhere else other than the intended destination.
The correct command you should use is
mv prog3a/stats.cpp prog3c/stats.cpp
This command should be run in the directory where both prog3a and prog3c folders exist (cd to it before running the command. This is assuming they're both inside the same directory).
A more specific answer can be provided if you tell us which command you initially ran specifically and the full paths of each folder.

How to open all mp3 files using windows command line?

If I have the following directory:
C:\Users\mkt\Desktop\Music\Tool\Lateralus
and want to open all files contained in the folder using cmd prompt. how could I do that?
I know that the following line will open one of them:
cd C:\Users\mkt\Desktop\Music\Tool\Lateralus\"01 - The Grudge.mp3"
But what about multiple files?
I am a noob at DOS and I really shouldn't be, but without practice you will never get better.
I am wondering, why it is opening your mp3 file with the cd command.
The cd command is used to switch directories, so this is something new for me.
I am a MAC OS user, so I could not test it, but if your given example worked, I think this should work too:
cd C:\Users\mkt\Desktop\Music\Tool\Lateralus\*.mp3
With the "*.mp3" you say, every mp3 file.
I hope this helps.

How to create a batch file in Mac?

I need to find a solution at work to backup specific folders daily, hopefully to a RAR or ZIP file.
If it was on PC, I would have done it already. But I don't have any idea to how to approach it on a Mac.
What I basically want to achieve is an automated task, that can be run with an executable, that does:
compress a specific directory (/Volumes/Audio/Shoko) to a rar or zip file.
(in the zip file exclude all *.wav files in all sub Directories and a directory names "Videos").
move It to a network share (/Volumes/Post Shared/Backup From Sound).
(or compress directly to this folder).
automate the file name of the Zip file with dynamic date and time (so no duplicate file names).
Shutdown Mac when finished.
I want to say again, I don't usually use Mac, so things like what kind of file to open for the script, and stuff like that is not trivial for me, yet.
I have tried to put Mark's bash lines (from the first answer, below) in a txt file and executed it, but it had errors and didn't work.
I also tried to use Automator, but it's too plain, no advanced options.
How can I accomplish this?
I would love a working example :)
Thank You,
Dave
You can just make a bash script that does the backup and then you can either double-click it or run it on a schedule. I don't know your paths and/or tools of choice, but some thing along these lines:
#!/bin/bash
FILENAME=`date +"/Volumes/path/to/network/share/Backup/%Y-%m-%d.tgz"`
cd /directory/to/backup || exit 1
tar -cvz "$FILENAME" .
You can save that on your Desktop as backup and then go in Terminal and type:
chmod +x ~/Desktop/backup
to make it executable. Then you can just double click on it - obviously after changing the paths to reflect what you want to backup and where to.
Also, you may prefer to use some other tools - such as rsync but the method is the same.

OSX Bash Script: Zip files in directory, Rename move and delete

I have the following directory and am having problems selecting the path:
Server HD/Library/FileMaker Server/Data/Backups/Nightly/NightlyBackups/Databases/*
A) How do I correctly Zip all the files in the * directory,
B) Rename the the Zip file, XXXX_XX_XX_Filemaker Nightly.zip
C) Move XXXX_XX_XX_Filemaker Nightly.zip to HD/Library/FileMaker Server/Data/Backups/Nightly/NightlyBackups/Nightly Zipped folder
Thank you,
John
First, man is your friend. The man command as in manual tells you how to use other commands:
$ man zip
Don't be overwhelmed by the amount of information. The important thing is to see the various command line parameters and some helpful examples. For example, if you want to include all subdirectories, you would need to use the --recurse-paths parameter. Compare this to the --recurse-patterns parameter.
You look like you're a pretty much of a beginner with shell scripting and using the shell on your Mac. Look at Take Control of the Mac Command Line with Terminal. It's a simple straightforward, not-overly-technical, non-programmer introduction to the command line, and into basic shell scripting. It's a great introduction.

Whats different when you executable a scripts in OSX?

I have a question I have been trying to fix for a while. I want to understand what's the difference between starting a script from the command line and making it executable and then running it from the Finder.
Because this is what I am experiencing;
I have a simple script called trash-files which contains this command:
trash ~/Downloads/*
When I run from the terminal it works as expected; however if I doubleclick the shell script in the finder I see this:
/Users/xx/Desktop/trash-files: line 1: trash: command not found
I hope anyone can tell me why this doesn't work as expected
trash is not a standard command in OS X. Is it something defined in your ~/.profile or a similar file? If so, these are not run for non-login shells, such as those created to run a script.
If you're using homebrew, you could run
brew install trash
which would install the necessary scripts to have the trash command work in the way you're expecting.
There is a folder in your home folder location called
.Trash
The "dot" in front of the folder name makes it hidden while searching for it in finder. You'll have to use Terminal to execute the following command:
cd ~/
ls -la
This will change the directory to the current logged in users home folder, then second command will list files and show hidden files. You can then run:
rm .Trash/*
This will remove everything inside the Trashcan on the dock.
So open TextEdit from the /Applications folder, go to "Format" and make it "Plain Text". Paste in the two lines below.
#!/bin/sh
rm ~/.Trash/*
Save the file as "emptyTrash.sh" (uncheck use txt extension). Save it to your Desktop or wherever you'd like. Then open Terminal, cd (change directory) to where the files is and run this command to make the script executable:
chmod +x emptyTrash.sh
Then you can execute the script by cd (changing directory) to path where the script is, and run:
./emptyTrash.sh
That's it.

Resources