using terminal

Joined
Jul 31, 2010
Messages
44
Reaction score
0
Points
6
Location
USA
when wanting to execute a command on a file do you always have to type in the whole directory as the filename? for instance to use the rm command can you just type to filename or do you have to list the whole address?
sorry im new to using terminal, i know this is a basic question, i just have only had success with using the whole address

thanks

mayflyTR
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
If you want to use a tool that requires a file be passed to it, you either have to be in that directory or you have to give the full path. Let's start with option one (be in the directory). The first thing you need to do is use cd to change your directory. Let's say for the sake of this post that the file is on your Desktop. To change to the Desktop, enter the following:
Code:
cd ~/Desktop
(~ is shorthand for your user directory). You can now do the rm command you posted because you are now in the directory of the file.

Option two: using the full path. This is much quicker as it involves only one command. Simply type the following (again assuming the file is on your Desktop):
Code:
rm ~/Desktop/work.docx

Note that using rm will not move the file to the trash - if you rm a file, it's gone.

Tip: If you start typing a file, directory or command, push tab to have bash autocomplete it for you (saves time, trust me).
 
OP
M
Joined
Jul 31, 2010
Messages
44
Reaction score
0
Points
6
Location
USA
thank you very much, i know i changed the question after you posted, i just wanted to broaden it..haha, thanks again!

mayflyTR
 
Joined
May 14, 2009
Messages
2,052
Reaction score
136
Points
63
Location
Near Whitehorse, Yukon
Your Mac's Specs
2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
May I add one? :)
To avoid making a mistake with the rm command I use the mv (Move) command.
This just moves the file to the Trash using the full path.

Code:
mv ~/Desktop/Junk.txt ~/.trash/
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top