-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lewisevans2007 <[email protected]>
- Loading branch information
lewisevans2007
committed
Aug 31, 2023
1 parent
8d98c2c
commit 1c08c9d
Showing
8 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python3 | ||
# Light builtins's (Python version) | ||
# cp - copy files or directories | ||
# A lightweight repository of useful shell commands | ||
# GitHub: https://www.github.com/lewisevans2007/light_builtins | ||
# Licence: GNU General Public License v3.0 | ||
# By: Lewis Evans | ||
|
||
import os | ||
import sys | ||
|
||
def main(args): | ||
if len(args) < 2: | ||
print("cp: missing file operand") | ||
return 1 | ||
if len(args) > 2: | ||
print("cp: extra operand") | ||
return 1 | ||
if not os.path.exists(args[0]): | ||
print("cp: cannot stat '" + args[0] + "': No such file or directory") | ||
return 1 | ||
if os.path.isdir(args[0]): | ||
print("cp: omitting directory '" + args[0] + "'") | ||
return 1 | ||
|
||
try: | ||
with open(args[0], 'r') as f: | ||
data = f.read() | ||
except: | ||
print("cp: cannot stat '" + args[0] + "': Permission denied") | ||
return 1 | ||
|
||
try: | ||
with open(args[1], 'w') as f: | ||
f.write(data) | ||
except: | ||
print("cp: cannot stat '" + args[1] + "': Permission denied") | ||
return 1 | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main(sys.argv[1:])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python3 | ||
# Light builtins's (Python version) | ||
# date - show the date and time | ||
# A lightweight repository of useful shell commands | ||
# GitHub: https://www.github.com/lewisevans2007/light_builtins | ||
# Licence: GNU General Public License v3.0 | ||
# By: Lewis Evans | ||
|
||
import sys | ||
import datetime | ||
|
||
def main(args): | ||
date_time = datetime.datetime.now() | ||
print(date_time) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main(sys.argv[1:])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python3 | ||
# Light builtins's (Python version) | ||
# mkdir - make directories | ||
# A lightweight repository of useful shell commands | ||
# GitHub: https://www.github.com/lewisevans2007/light_builtins | ||
# Licence: GNU General Public License v3.0 | ||
# By: Lewis Evans | ||
|
||
import os | ||
import sys | ||
|
||
def main(args): | ||
for arg in args: | ||
os.mkdir(arg) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main(sys.argv[1:])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python3 | ||
# Light builtins's (Python version) | ||
# mv - move files or directories | ||
# A lightweight repository of useful shell commands | ||
# GitHub: https://www.github.com/lewisevans2007/light_builtins | ||
# Licence: GNU General Public License v3.0 | ||
# By: Lewis Evans | ||
|
||
import os | ||
import sys | ||
|
||
def main(args): | ||
if len(args) < 2: | ||
print("mv: missing file operand") | ||
return 1 | ||
if len(args) > 2: | ||
print("mv: extra operand") | ||
return 1 | ||
if not os.path.exists(args[0]): | ||
print("mv: cannot stat '" + args[0] + "': No such file or directory") | ||
return 1 | ||
if os.path.isdir(args[0]): | ||
print("mv: omitting directory '" + args[0] + "'") | ||
return 1 | ||
|
||
try: | ||
os.rename(args[0], args[1]) | ||
except: | ||
print("mv: cannot stat '" + args[1] + "': Permission denied") | ||
return 1 | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main(sys.argv[1:])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python3 | ||
# Light builtins's (Python version) | ||
# rm - remove files or directories | ||
# A lightweight repository of useful shell commands | ||
# GitHub: https://www.github.com/lewisevans2007/light_builtins | ||
# Licence: GNU General Public License v3.0 | ||
# By: Lewis Evans | ||
|
||
import os | ||
import sys | ||
|
||
def main(args): | ||
for arg in args: | ||
os.remove(arg) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main(sys.argv[1:])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python3 | ||
# Light builtins's (Python version) | ||
# rmdir - remove empty directories | ||
# A lightweight repository of useful shell commands | ||
# GitHub: https://www.github.com/lewisevans2007/light_builtins | ||
# Licence: GNU General Public License v3.0 | ||
# By: Lewis Evans | ||
|
||
import os | ||
import sys | ||
|
||
def main(args): | ||
for arg in args: | ||
os.rmdir(arg) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main(sys.argv[1:])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
# Light builtins's (Python version) | ||
# touch - create a file with the current time | ||
# A lightweight repository of useful shell commands | ||
# GitHub: https://www.github.com/lewisevans2007/light_builtins | ||
# Licence: GNU General Public License v3.0 | ||
# By: Lewis Evans | ||
|
||
import os | ||
import sys | ||
|
||
def main(args): | ||
if len(args) < 1: | ||
print("touch: missing file operand") | ||
return 1 | ||
if len(args) > 1: | ||
print("touch: extra operand") | ||
return 1 | ||
if os.path.exists(args[0]): | ||
print("touch: cannot create file '" + args[0] + "': File exists") | ||
return 1 | ||
try: | ||
with open(args[0], 'w') as f: | ||
f.write("") | ||
except: | ||
print("touch: cannot create file '" + args[0] + "': Permission denied") | ||
return 1 | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main(sys.argv[1:])) |