I'm wondering if there is a way to create and open multiple files in terminal using a custom one-liner terminal command using OSX 10.9.4.
like $ makemore test.rb test2.rb
then it opens using my default Sublime Text3
I found the custom command to create and open a single file.
lazy()
{
touch $1
open $1
}
Is this possible to make something that makes, then opens multiple files?
P.S. Thanks to this Stackoverflow question for how to make custom command to create and open a single file. How can I create and open a file from terminal with a single command?
lazy() { for x; do touch "$x"; open "$x"; done; }
Then call it with a list of file names.
Related
I'm using the newest version of macOS Monterey.
Sometimes I have to merge/combine all files that are in a specific folder into one txt file.
I currently do that by typing this in Terminal:
cd /Users/my_name/Desktop/test_folder ; cat * >merged.txt
This will merge/combine all files in folder test_folder into one file called merged.txt. The file merged.txt will get saved into the folder test_folder.
Every time I need this I have to open Terminal copy/paste the command and replace test_folder with the right folder name, since it's not always the same.
I want to make this easier by just make a right click on a folder, go to Quick Actions and select e.g. Merge all files to merge/combine all files inside the folder I just clicked on.
But I stuck at getting the folder name. How can I dynamically get the folder name and path I clicked on to start this Quick Action instead of the hard coded /Users/my_name/Desktop/test_folder?
Or, is there another and easier solution?
This is what I have so far:
I wouldn’t do this with AppleScript, especially if all it’s ultimately doing is calling out to a shell script.
Stick with the Run Shell Script action except change the option for passing the input as arguments rather than to stdin.
The folders selected in Finder will then be available to your script via $#, so you can do something like:
for d in "$#"; do
cat "$d"/* > "$d/merged.txt"
open -R "$d/merged.txt"
done 2>/dev/null
This loops through the selected directories and concatenates the files to merged.txt in the respective directory. The open -R line reveals the merged.txt file in Finder.
Errors are written to /dev/null, i.e. discarded, as cat will throw an error if any of the directories, themselves, contain directories.
Instead of adding a Run Shell Script to your workflow, try adding a Run AppleScript command instead. Copy this following AppleScript code to the Run AppleScript command.
on run {input, parameters}
try
do shell script "cd " & quoted form of POSIX path of input & " && cat *.txt > merged.txt"
on error
try
do shell script "cd " & quoted form of POSIX path of input & " && rm merged.txt"
end try
end try
end run
Hi i am not able to figure out what is the command for creating a file from terminal in Goorm ide . Just to make clear i want to create new file only from terminal not by gui.
Just like in other Linux terminals, you can type touch filename to create a file via goormIDE terminal.
FYI:
Type mkdir foldername to create a directory
Type goorm filename to open a file in goormIDE editor
goormide is ubuntu os.
so you can create files by typing common linux commands like touch data.json
Either I'm too stupid or I can't find the right command.
How can I create a simple YAML file using the ZSH terminal?
You can create yml file like these commands
echo "basic" > basic.yml or touch simple.yml
YAML is just a format so you can create any text file and just add an .yml or .yaml extension.
Command for creating files in zsh is touch
touch test.yaml
What people usually do is to just open a terminal text editor like nano or vim add the content and save as *.yml or *.yaml
I need to work with different files in the script. The easy and convenient way to do it is to use "Drag and drop". But.
Drag and drop files to a bash script causes "Permission denied" when you output data to a file.
I use git-bash on Windows 10.
#!/bin/bash
echo "123" > out123.txt
sleep 5
When I run script in common way (I double click on it) it works well.
When I drag and drop a file (from the same folder) on the script:
#bash: out123.txt: Permission denied
Upd: It's for people who came from google:
How to get dropped data within bash script.
It's usual argument. Code example [1] or [2]:
for var in "$#"
do
echo "$var"
done
I have a text file fold.txt that contains one line fold_nam:
$ cat fold.txt
fold_nam
This name in the the text file is an output that was created during a program run of a folder's name that now contains other files that I need to work with.
I am writing a big script and now I need to enter this folder and I need to get the name from the text file. I tried several things but cannot really work it out.
There's no need to use cat:
cd $(<fold.txt)
If you want to read the line into a variable: read -r folder_name < fold.txt
You should be able to do this:
cd $(cat fold.txt)
or
cd `cat fold.txt`