This repo contains some useful and repetitive ubuntu commands (especially for data scientists).
find . -type f | wc -l
ls /folder_address/ | wc -l
--> Reference1
--> Reference2
Find and count total number of files in particular directory with specific extension and (ends with specific string):
find ./ -mindepth 1 -type f -name "*_mono.mp3" -printf x | wc -c
ls -R > output_list_all_files.txt
--> Reference1
for file in *.mp3; do mp3info -p "%S\n" "$file"; done | paste -sd+ | sed 's+\(.*\)+(\1)/60+' | bc
--> above command prints result in minutes
--> Reference1
--> Reference2
soxi -D * | awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'
or
ls|grep ".wav"|parallel -j$(nproc) soxi -D {}|awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'
--> Reference1
--> Reference2
find *.mp3 | sed 's:\ :\\\ :g'| sed 's/^/file /' > fl.txt; ffmpeg -f concat -i fl.txt -c copy output.mp3; rm fl.txt
or
ffmpeg -f concat -safe 0 -i <( for f in *.wav; do echo "file '$(pwd)/$f'"; done ) output.wav
--> Reference1
--> Reference2
--> Reference3
--> Reference4
ffmpeg -i input_file.mp3 -f segment -segment_time 3 -c copy out%03d.mp3
--> Reference1
ffmpeg -i input.mp3 -acodec copy -ss START_TIME -to END_TIME output.mp3
or
ffmpeg -i input.mp3 -ss 1.9 -to 3.5 -c copy output.mp3
or for folder based usage of above command, one can use below command:
for i in *.mp3; do ffmpeg -i "$i" -ss 0.0 -to 20.0 -c copy "../mp3_files_first_20_seconds/$i"; done
--> Reference1
--> Reference2
for i in *.mp3; do ffmpeg -i "$i" -f wav "${i%}.wav"; done
--> Reference1
for i in *.wav; do ffmpeg -i "$i" -f mp3 "${i%}.mp3"; done
--> Reference1
find . -name '*.wav' | xargs mv --target-directory=/path/to/dest_dir/
--> Reference1
grep "hello" train_data.csv
--> will just show the results
grep -c "hello" train_data.csv
--> will count number of results
ls | head -10
--> Reference1 [great refrence for ls
command]
ls | tail -10
--> Save in-place and replace all the word "original" to "new" word in "predictions_all.json" file.
awk '{gsub(/original/,"new phrase")}1' ./input_manifest.json > ./output_manifest.json
or
sed -i 's/original/new/g' predictions_all.json
--> Reference1
head -13 file_name | tail +13
or
sed -n '13p' file.txt
or
sed -n '20,25p' lines.txt
or
awk 'NR==5' lines.txt
or
awk 'NR>=20 && NR<=25' lines.txt
--> Reference1
--> Reference2
ffmpeg -ss 1 -i input.wav -to 20 -c copy output.wav
--> above command, will cut from second 1 to 20.
--> Reference1
--> Reference2
ffmpeg -i stereo_input.wav -ac 1 mono_output.wav
find . -name '*.mp3' -exec ffmpeg -i '{}' -ac 1 'mono_{}' \; for i in *.mp3; do ffmpeg -i "$i" -ac 1 "./output_folder/$i"; done
or
find . -name '*.mp3' -exec ffmpeg -i '{}' -ac 1 '{}_mono.mp3' \; for i in *.wav; do ffmpeg -i "$i" -ac 1 "${i%.*}.wav"; done
--> Reference1
--> Reference2
--> Reference3
ffmpeg -i stereo.wav -filter_complex "[0:a]channelsplit=channel_layout=stereo:channels=FR[right]" -map "[right]" front_right.wav
or
for i in *.mp3; do ffmpeg -i "$i" -filter_complex "[0:a]channelsplit=channel_layout=stereo:channels=FR[right]" -map "[right]" "./output_folder/$i"; done
--> Reference1
ffmpeg -i stereo.wav -filter_complex "[0:a]channelsplit=channel_layout=stereo:channels=FL[left]" -map "[left]" front_left.wav
or
for i in *.mp3; do ffmpeg -i "$i" -filter_complex "[0:a]channelsplit=channel_layout=stereo:channels=FL[left]" -map "[left]" "./output_folder/$i"; done
--> Reference1
date "+%H:%M:%S %d/%m/%y"
--> Reference1
at now +8 hours
at> python3 run_test.py # type your desired command
--> press ctrl+D
to save the commands
--> Reference1
--> Reference2
--> Reference3
for i in *.mp3; do ffmpeg -i "$i" -ac 1 "./output_folder/$i"; done
or
for i in *.wav; do python run_code.py "$i"; done
--> "$i" is the name of input file
--> Reference1
ls > output_directory/ls_output.txt
--> To redirect the output of a command to a file, type the command, specify the > or the >> operator, and then provide the path to a file you want to the output redirected to.
--> Reference1
ffmpeg -i input.mp3 -acodec copy -ss START_TIME -to END_TIME output.mp3
ffmpeg -i input.mp3 -ss 1.9 -to 3.5 -c copy output.mp3
for i in *.mp3; do ffmpeg -i "$i" -ss 0.0 -to 20.0 -c copy "../mp3_files_20_first_seconds/$i"; done
--> Reference1
--> Reference2
ffmpeg -i input.mp3 -acodec pcm_s16le -ac 1 -ar 16000 output.wav
for i in ./*.wav; do ffmpeg -i "$i" -acodec pcm_s16le -ac 1 -ar 16000 "output_folder/$i"; done
--> Reference1
sudo passwd tom
sudo passwd root
--> Reference1
--> Reference2
cut -d: -f1 /etc/passwd
--> Reference1
Move all files (but not folders) out of nested sub-directories into another folder (e.g., from Downloads
folder to Videos
folder):
find ~/Downloads/ -type f -print0 | xargs -0 mv -t ~/Videos
--> Reference1
ffmpeg -i input.wav -af silencedetect=n=-40dB:d=1.0 -f null -
ffmpeg -i input.wav -af silencedetect=n=-40dB:d=1.0 -f null - 2> ./silence.txt
--> Reference1
--> Reference2
--> Reference3
--> Reference4: Remove the Silent Parts of a Video Using FFmpeg and Python [Important & Useful]
ffmpeg -i sample.avi -q:a 0 -map a sample.mp3
--> Reference1
--> Reference1
--> Reference2
--> Reference3
--> Reference4
--> Reference5
--> Reference1
--> Reference2
--> Reference3
sudo swapoff -a; sudo swapon -a
--> Reference1
--> Reference1
--> Reference2
pkill -U username
--> Reference1
sudo echo 1 > /proc/sys/vm/overcommit_memory
--> Reference1
--> Reference2
/bin/bash
or chsh -s /bin/bash
--> Reference1
--> Reference2