The name of the currently executing script is: ./BashScript.shWe can verify the value at the first index; we got ./BashScript.sh, the basename of the currently executing script. Using $0 VariableTo get the current script’s directory in a Bash, use the $0 array variable. In Bash, the...
/bin/bash# Change the current directory to the script directorypushd$(dirname$0)>/dev/null# Store the current directory in a variablescript_dir=$PWDecho"The script is located in:$script_dir"# Return to the previous directorypopd>/dev/null# Output:# The script is located in: /path/to/yo...
Bash: get absolute path to current script Bash shell path relative to current script Bash: while loop - break - continue Functions in Linux shell (bash) Create temporary directory on Linux with Bash using mktemp Count number of lines in a file and divide it by number of seconds in...
System.out.println...(directory.getAbsolutePath());//获取绝对路径 }catch(Exceptin e){} File.getCanonicalPath()和File.getAbsolutePath...,返回当前的路径加上你在new File()时设定的路径 # 至于getPath()函数,得到的只是你在new File()时设定的路径 比如当前的路径为 C:\test : File directory ...
Start by creating the bash script:nano inodesdisk.shPaste in the following code – it will check inodes in descending order as well as show disk usage in a given directory:#!/bin/bash find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn du -shc * | sort -...
So, let's dive in and learn how to get the source directory of a Bash script. Understanding the $0 Parameter The $0 parameter in Bash holds the name of the script that is currently running. It is a special parameter that can be used to retrieve the name of the script at runtime. Th...
$file/etc/etc: directory #使用-i选项,可以MIME类型的格式显示文件类型信息 $file-i /etc/inittab/etc/inittab: text/plain; charset=us-ascii $file-i /etc/init.d/network/etc/init.d/network: text/x-shellscript; charset=us-ascii $file-i /usr/bin/file/usr/bin/file: application/x-executable...
cd $TargetDirectoryecho"Deleting stale files in $TargetDirectory."if["$PWD"!="$TargetDirectory"]then# 防止偶然删错目录.echo"Wrong directory!"echo"In $PWD, rather than $TargetDirectory!"echo"Bailing out!"exit $E_WRONG_DIRECTORYfirm-rf *# 删除文件rm.[A-Za-z0-9]*# 删除点文件echo"Done....
/bin/bash # FTP服务器信息 FTP_SERVER="ftp.example.com" FTP_USER="username" FTP_PASS="password" FTP_DIR="/path/to/ftp/directory" LOCAL_DIR="/path/to/local/directory" # 获取FTP目录中的文件列表 ftp -n $FTP_SERVER <<EOF user $FTP_USER $FTP_PASS cd $FTP_DIR ls -l EOF # 将输出...
/bin/bash# 定义进程名和文件名process_name="nginx"file_name="error.log"directory_to_search="/var/log"# 检查进程是否在运行pgrep -x$process_name> /dev/nullif[$?-ne0];then# 如果进程没有在运行,启动它echo"Starting$process_name..."sudo service$process_namestartelseecho"$process_nameis ...